A functional relation which is satisfied by $\cos x$ and $\sin x$
Let me put together all in an answer.
Define $h(x):=g(x)+if(x)$. Then $(\star)$ is equivalent to $$h(x+y)=h(x)h(y).$$
If $h(x)=0$ for some $x$ then $h$ is identically zero. Assume that $h$ never vanishes.
Let $\{a_i\}_{i\in I}$ be a Hamel basis of $\mathbb{R}$ as $\mathbb{Q}$-vector space.
Put $b_i:=h(a_i)$ and define $\hat{h}(x):=e^{r(x)}$, where $r(x)$ is the unique function determined by $r(x+y)=r(x)+r(y)$, and $r(a_i)=c_i$, where $c_i$ is any number such that $e^{c_i}=b_i$, and in the sequel I will not use anything beyond this).
Then $u(x):=h(x)/\hat{h}(x)$ satisfies $u(x+y)=u(x)u(y)$, and $u(0)=1$.
If $x=\sum\frac{p_i}{q_i}a_i$, with $(p_i,q_i)=1$, then $u(x)^{\prod q_i}=\prod u(\frac{p_i}{q_i}a_i)^{\prod q_i}=1$. The last equality is because $u(\frac{p_i}{q_i}a_i)^{q_i}=u(p_ia_i)=u(a_i)^{p_i}=1$
Then $u$ is a character (group homomorphism from $\mathbb{R}$ to the unit circle).
Converselly, for every $r$ such that $r(x+y)=r(x)+r(y)$ and a character $u$ of $\mathbb{R}$ we get $h(x):=e^{r(x)}u(x)$, which satisfies $h(x+y)=h(x)h(y)$. This gives us $$f(x):=\text{Im}(h(x))$$ and $$g(x):=\text{Re}(h(x)).$$
Now, to finish, we need to 'compute' all characters of the additive group $\mathbb{R}$.
Notice that each $\frac{p}{q}\mapsto u(\frac{p}{q}a_i)$ is a character of the additive group $\mathbb{Q}$. And conversely, if $u_i$ are characters of $\mathbb{Q}$ then $$u(x)=u\left(\sum\frac{p_i}{q_i}a_i\right):=\prod u_i\left(\frac{p_i}{q_i}\right)$$ satisfies $u(x+y)=u(x)u(y)$, and $u(0)=1$.
So, what we need is to 'compute' all characters of $\mathbb{Q}$. This can be read here, for example.
Notice the above gives us a way to produce all the solutions $h$, but it is not a unique writing of them. If we get two $\hat{h}$'s which quotient is a character of $\mathbb{R}$ then we can obtain the same $h$ from them by dividing by this character.