I hope I have interpreted this question properly, but I believe the way to go about solving this is to set up the following error integral:
$ E(a_0, a_1, a_2) = \int_{0}^{\pi} 2 ( x - \frac{a_0}{2} - a_1 \cos(x) - a_2 \cos(2 x))^2 dx $
and then minimizing $E(a_0, a_1, a_2)$.
As J.M. pointed out, $|x|$ is even and the $\sin$'s will just increase the error so they can be left out. The above integral can be done easily, if not tediously, by hand but I'm too lazy, so I just asked Mr. Wolfram which yielded:
$ \frac{\pi a_0^2}{2} - \pi^2 a_0 + \pi a_1^2 + \pi a_2^2 + 8 a_1 + \frac{2 \pi^3}{3}$
This is a (hyper?) paraboloid so let's use our standard tricks:
$ \frac{\partial E(a_0, a_1, a_2)}{\partial a_0} = \pi a_0 - \pi^2 = 0 \to a_0 = \pi $ $ \frac{\partial E(a_0, a_1, a_2)}{\partial a_1} = 2 \pi a_1 + 8 = 0 \to a_1 = \frac{-4}{\pi} $ $ \frac{\partial E(a_0, a_1, a_2)}{\partial a_2} = 2 \pi a_2 = 0 \to a_2 = 0 $
Just by eye-balling it you can see that the second derivative in each is positive, so that the paraboloid is increasing and the points just calculated represent the unique global minimum.
Comparing the plot of $|x|$ and $\frac{\pi}{2} - \frac{4 cos(x)}{\pi}$ on $[0, \pi]$, we can see it sort of matches up:
