You know that
$$f(x) = \frac{a_0}{2} + \sum_{n = 1}^\infty (a_n \cos(nx) + b_n\sin(nx)), \quad x \in [-\pi,\pi].$$
So
$$\int_{-\pi}^\pi f(x)g(x)\, dx = \frac{a_0}{2}\int_{-\pi}^\pi g(x)\, dx + \sum_{n = 1}^\infty \left(a_n \int_{-\pi}^\pi \cos(nx)g(x)\, dx + b_n \int_{-\pi}^\pi \sin(nx)g(x)\, dx\right).$$
This step is justified by the uniform convergence assumptions given in the problem. By definition of the Fourier coefficients $\alpha_n$ and $\beta_n$, we have
$$\pi \alpha_0 = \int_{-\pi}^\pi g(x)\, dx,$$
$$\pi \alpha_n = \int_{-\pi}^\pi \cos(nx)g(x)\, dx,\quad n \ge 1$$
and
$$\pi \beta_n = \int_{-\pi}^\pi \sin(nx)g(x)\, dx,\quad n \ge 1.$$
Therefore
$$\int_{-\pi}^\pi f(x)g(x)\, dx = \frac{\pi a_0\alpha_0}{2} + \sum_{n = 1}^\infty (\pi a_n\alpha_n + \pi b_n \beta_n),$$
or
$$\int_{-\pi}^\pi f(x)g(x)\, dx = \frac{a_0 \alpha_0}{2} + \sum_{n = 1}^\infty (a_n \alpha_n + b_n \beta_n).$$
Try replacing $L$ with $\pi$ in the definition you have for the interval $[-L,L]$. Notice that you get back the original definition for $[-\pi,\pi]$. The generalization comes from wanting the cosine and sine parts to still be periodic over the interval $[-L,L]$, just as they were over $[-\pi,\pi]$.
For the series on the interval $[0,2\pi]$, a useful trick is to look at a new function, $g:[-\pi,\pi]\rightarrow\mathbb{R}$ defined by $g(x)=f(x+\pi)$. Then compute the Fourier series for $g(x)$ instead of $f(x)$, using the formula you already know.
Best Answer
Big Hint
$$\cos^2(x)=\frac{1+\cos(2x)}{2}.$$