This is an expansion of my comments to the question.
Let us observe that definition of derivative is a local concept ie it deals with the behavior of a function at a point (in reality an immediate neighborhood of a point). The equation in question $$\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}=\cos x\tag{1}$$ has to be understood as valid in some interval of values of $x$ and not just at some point, say $0$. Just looking at $x=0$ does not give much information about $f$ (in that case even $f(x) =x$ works as a solution to the equation).
Let us then assume that the above equation holds for all values of $x$. We prove that if there exists a solution to the above equation then it must equal $f(x)=\sin x+f(0)$.
Let us first take an interval $[a, b] $ where $\cos x$ is monotone (eg $a=0,b=\pi$) and let $x\in[a, b] $. Let us define $$x_i=a+\frac{i(x-a)} {n}, i=0,1,2,\dots,n$$ and then we have $$f(x) - f(a) =\sum_{i=1}^n f(x_i) - f(x_{i-1})=\sum_{i=1}^nf'(\xi_i)\cdot\frac{x-a}{n}=\frac{x-a}{n}\sum_{i=1}^n\cos \xi_i\tag{2}$$ where $\xi_i\in(x_{i-1},x_i)$. The above relation holds for all values of $n$ and some suitable values of $\xi_i$ (based on $n$). However the sum equals $f(x) - f(a)$ no matter what value of $n$ is chosen. And therefore the equation holds when $n\to\infty$. Due to the monotone nature of $\cos$ in $[a, b] $ the sum $\sum\cos \xi_i$ lies between $\sum\cos x_{i-1}$ and $\sum\cos x_i$. One can use the formula for sum of cosines of angles in arithmetic progression to evaluate these two sums in explicit manner.
We have $$\frac{x-a}{n}\sum_{i=1}^n\cos x_i=\frac{x-a}{n}\cdot\frac{\sin ((x-a) /2)}{\sin((x-a)/2n)}\cdot\cos ((x_1+x_n)/2)$$ and the above tends to $$2\sin((x-a)/2)\cos ((x+a) /2)=\sin x-\sin a$$ The other sum $((x-a) /n)\sum\cos x_{i-1}$ also tends to same limit as $n\to\infty$. It follows from $(2)$ that $$f(x) - f(a) =\sin x-\sin a$$ For $a=0$ we get $f(x) =\sin x+f(0)$ for $x\in [0,\pi]$. Using intervals $[k\pi, (k+1)\pi]$ for all integers $k$ one can extend the above result for all values of $x$.