Let $f \in C[0,2\pi]$ and where $a_k, b_k $ are its Fourier coefficients. Assume there are finitely many nonzero coefficients.
Then $||f||^2_2=2\pi a^2_0 \ + \pi\sum_{k=1}^{\infty}(a_k^2+b_k^2).$
I know that this identity holds for any function on interval $[0,2\pi]$ where $\int f^2 < \infty$.
How can I show the above identity holds?
Recall that $L_\mathbb{R}^2[0, 2\pi]$, the space of all real square-integrable functions on $[0, 2\pi]$, is a Hilbert space equipped with the inner product:
$$\langle f, g \rangle = \int_0^{2\pi} f(t)g(t)\,dt\quad \forall f, g \in L^2_\mathbb{R}[0, 2\pi]$$
For an orthonormal basis $(e_n)_{n=1}^\infty$ of a Hilbert space $X$ the Parseval identity holds:
$$\|x\|^2 = \sum_{n=1}^\infty |\langle x, e_n\rangle|^2, \quad\forall x\in X$$
In particular, the set of functions $$B = \left\{\frac1{\sqrt{2\pi}}\right\}\cup \left\{\frac{1}{\sqrt{\pi}}\sin nx : n \in \mathbb{N}\right\} \cup \left\{\frac{1}{\sqrt{\pi}}\cos nx : n \in \mathbb{N}\right\}$$ is an orthonormal basis for $L^2[0,2\pi]$ so we have:
\begin{align} \|f\|_2^2 &= \left\langle f, \frac1{\sqrt{2\pi}}\right\rangle^2 + \sum_{n=1}^\infty\left(\left\langle f, \frac{1}{\sqrt{\pi}}\sin nx\right\rangle^2 + \left\langle f,\frac{1}{\sqrt{\pi}}\cos nx\right\rangle^2\right)\\ &= \frac1{2\pi}\left(\int_0^{2\pi}f(t)\,dt\right)^2 + \frac{1}{\pi}\sum_{n=1}^\infty\left(\left(\int_0^{2\pi}f(t)\sin nt\,dt\right)^2 + \left(\int_0^{2\pi}f(t)\cos nt\,dt\right)^2\right)\\ \end{align}
Now, it seems your Fourier coefficients are defined as:
$$a_0 = \frac{1}{2\pi}\int_0^{2\pi} f(t)\,dt$$ $$a_n = \frac{1}{\pi}\int_0^{2\pi} f(t)\cos nt \,dt, \quad n\in\mathbb{N}$$ $$b_n = \frac{1}{\pi}\int_0^{2\pi} f(t)\sin nt \,dt, \quad n\in\mathbb{N}$$
so we can recognize them in the above formula:
\begin{align} \|f\|_2^2 &= 2\pi\left(\frac1{2\pi}\int_0^{2\pi}f(t)\,dt\right)^2 + \pi\sum_{n=1}^\infty\left(\left(\frac{1}{\pi}\int_0^{2\pi}f(t)\sin nt\,dt\right)^2 + \left(\frac{1}{\pi}\int_0^{2\pi}f(t)\cos nt\,dt\right)^2\right)\\ &= 2\pi a_0^2 + \sum_{n=1}^\infty \left(a_n^2 + b_n^2\right) \end{align}
We obtain the desired result.
This holds for any $f \in L_\mathbb{R}^2[0, 2\pi]$, so in particular it holds for $f \in C_\mathbb{R}[0, 2\pi] \subseteq L_\mathbb{R}^2[0, 2\pi]$, as continuous functions are square-integrable.