Changing integral and summation Let 
$$ f(x)=\left(\sum_{n=1}^\infty \frac{\cos(nx)}{2^n}\right)^2  $$
$$\hat{f}(n) = \frac{1}{2\pi}\int_0^{2\pi} \left(\sum_{n=1}^\infty \frac{\cos(nx)}{2^n}\right)^2 e^{-inx} dx$$
Easy to see the series converges uniformly, so we can interchange the sum with the integral. What's bothering me is the power of $2$. How do I change it correctly? Is it: 
$$\hat{f}(n) = \frac{1}{2\pi} \sum_{n=1}^\infty \left( \int_0^{2\pi}  \frac{\cos(nx)}{2^n}\right)^2 e^{-inx} dx$$
 A: First, write $\displaystyle\int_{0}^{2\pi}\left(\sum_{n = 1}^{\infty}\dfrac{\cos(nx)}{2^n}\right)^2\,dx = \displaystyle\int_{0}^{2\pi}\sum_{m = 1}^{\infty}\sum_{n = 1}^{\infty}\dfrac{\cos(mx)}{2^m}\dfrac{\cos(nx)}{2^n}\,dx$. 
Now, interchange the integral and the double sum to get $\displaystyle\sum_{m = 1}^{\infty}\sum_{n = 1}^{\infty}\int_{0}^{2\pi}\dfrac{\cos(mx)}{2^m}\dfrac{\cos(nx)}{2^n}\,dx$. 

EDIT: Now that you have changed the question significantly, it looks like you are trying to find the Fourier series coefficients for $f(x)^2$ where $f(x) = \displaystyle\sum_{n = 1}^{\infty}\dfrac{\cos(nx)}{2^n}$. If this is indeed the case, since you already have the Fourier series coefficeints for $f(x)$, I would recommend using the fact that multiplication in the time domain corresponds to convolution in the frequency domain. 
Specifically, if we know that $f(x) = \displaystyle\sum_{n = -\infty}^{\infty}a_ne^{inx}$ and $g(x) = \displaystyle\sum_{n = -\infty}^{\infty}b_ne^{inx}$, then $f(x)g(x) = \displaystyle\sum_{n = -\infty}^{\infty}c_ne^{inx}$ where $c_n = \displaystyle\sum_{k = -\infty}^{\infty}a_kb_{n-k}$. 
