Let $f(x) = a x^3+bx^2 + c x+d$. The exact result is
$$
\int _{-\pi}^{\pi}\bigg(\cos(x)-f(x)\bigg)^2\,dx = \frac{2 \pi ^7 a^2}{7}+\frac{2}{5} \pi ^5 \left(2 a c+b^2\right)+\frac{2}{3} \pi ^3 \left(2 b
d+c^2\right)+\pi \left(8 b+2 d^2+1\right)
$$We want to minimize this in terms of $a,b,c,d$. By symmetry, we can make the ansatz $a=c=0$: this is plausible because cosine is even, so an even polynomial should be the best fit over a symmetric interval. This yields
$$
\int _{-\pi}^{\pi}\bigg(\cos(x)-(bx^2+d)\bigg)^2\,dx = \frac{2 \pi ^5 b^2}{5}+\frac{4}{3} \pi ^3 b d+8 \pi b+2 \pi d^2+\pi
$$Taking the gradient and solving for $b,d$, we have
$$
\nabla_{b,d} = \left(\frac{4 \pi ^5 b}{5}+\frac{4 \pi ^3 d}{3}+8 \pi ,\frac{4 \pi ^3 b}{3}+4 \pi d\right)
$$
$$\nabla_{b,d}=(0,0)\Rightarrow
(b,d) = \left(-\frac{45}{2 \pi ^4},\frac{15}{2 \pi ^2}\right) \approx \left(-0.230985, 0.759909\right)
$$These values give the minimum value of the integral as $\pi -\frac{90}{\pi ^3}\approx 0.238955$. A similar analysis can be carried out if we don't initially assume $a=c=0$, but we get the same result.