I am unable to derive the Hamiltonian for the electromagnetic field, starting out with the Lagrangian $$ \mathcal{L}=-\frac{1}{4}F^{\mu\nu}F_{\mu\nu}-\frac{1}{2}\partial_\nu A^\nu \partial_\mu A^\mu $$ I found: $$ \pi^\mu=F^{\mu 0}-g^{\mu 0}\partial_\nu A^\nu $$ Now $$ \mathcal{H}=\pi^\mu\partial_0 A_\mu-\mathcal{L} $$ Computing this, I arrive at: $$ \mathcal{H}=-\frac{1}{2}\left[\partial_0 A_\mu\partial_0 A^\mu+\partial_i A_\mu\partial_i A^\mu\right]+\frac{1}{2}\left[\partial_i A_i\partial_j A_j-\partial_j A_i\partial_i A_j\right] $$ The right answer, according to my exercise-sheet, would be the first to terms. Unfortunately the last two terms do not cancel. I have spent hours on this exercise and I am pretty sure, that I did not commit any mistakes arriving at this result as I double checked several times. My question now is: did I start out right and am I using the right scheme? Is this in principle the way to derive the Hamiltonian, or is it easier to start out with a different Lagrangian maybe using a different gauge? Any other tips are of course also welcome. Maybe the last two terms do actually cancel and I simply don't realize it. Texing my full calculation would take a very long time so I am not going to post it, but as I said, it should be correct. But if everything hints at me having committed a mistake there, I will try again.
Edit:
After reading and thinking through Stephen Blake's answer, I realized that one can get rid of the last two terms in $H$, even though they do not vanish in $\mathcal{H}$. This is done by integrating the last term by parts and dropping the surface term, leaving $A_i\partial_j\partial_i A_j$. One can now proceed to combine the last two terms: $$ \partial_i A_i\partial_j A_j+A_i\partial_j\partial_i A_j=\partial_i(A_i\partial_j A_j) $$ This can be converted into a surface integral in $H$ which can be assumed to vanish, leaving us with the desired "effective" $\mathcal{H}$.