Proof that sum^infty of 1/n^2 = ...

I am trying to prove $\displaystyle \frac{x^{2}}{2} = \pi x - \frac{\pi^{2}}{3} + 2\displaystyle \sum^{\infty}_{n = 1} \frac{cos(nx)}{n^{2}}$ for $0 \leq x \leq 2 \pi$. I've done quite a lot:

Taking derivative of both sides and using part (a), we see that $\displaystyle \frac{x^{2}}{2}$ and $\displaystyle \pi x + 2\displaystyle \sum^{\infty}_{n = 1} \frac{cos(nx)}{n^{2}}$ differ by at most a constant on $\displaystyle 0 < x < 2 \pi$ (in part (a) I have basically shown that the derivative of each side is equal). Evaluating at $\displaystyle $\pi$$, we see that the constant difference is $\displaystyle \frac{\pi^{2}}{3}$, which proves the equality. Likewise evaluating at 0 and $\displaystyle 2 \pi$ we obtain the identity.

(Note, this argument depends on the claim that $\displaystyle \displaystyle \sum^{\infty}_{n = 1} \frac{1}{n^{2}} = \frac{\pi}{6}$, at the point when I evaluate at $\displaystyle \pi$. ...

So here's where I'm stuck. I have a hint that I'm supposed to use the following theorem:

If a function $\displaystyle f$ is continuous and periodic on $\displaystyle [0, 2 \pi]$ with period $\displaystyle 2 \pi$, then, using the usual notation about $\displaystyle a_{n}$ and $\displaystyle b_{n}$, $\displaystyle \frac{1}{\pi} \displaystyle \int^{2 \pi}_{0} |f(t)|^{2}dt = \frac{a_{0}^{2}}{2} + \sum^{\infty}_{n = 1}(a_{n}^{2} + b_{n}^{2})$.

My first question is, since my function isn't periodic, how do I use this theorem?

Anyway, I started trying this for the function I'm working with, but what I get is: $\displaystyle \frac{1}{\pi} \displaystyle \int^{2 \pi}_{0}\frac{x^{4}}{4}dx =$

$\displaystyle \Bigl( \frac{1}{\pi} \int^{2 \pi}_{0} \frac{x^{2}}{2}dx \Bigr)^{2}/2 + \sum^{\infty}_{n = 1} \Bigl( \frac{1}{\pi} \int^{2 \pi}_{0} \frac{x^{2}}{2}cos(nx) dx \Bigr)^{2} + \Bigl( \frac{1}{\pi} \int^{2 \pi}_{0} \frac{x^{2}}{2}sin(nx) dx \Bigr)^{2}$

Now I have to say, already this looks messed up. Am I doing something wrong?