Free Scalar Field Hamiltonian derivation 
From David Tong's notes: How do we derive
  $$ H = \int\frac{d^3p}{(2\pi)^3}\omega_p[ a_p^\dagger a_p + \frac{1}2(2\pi)^3\delta^{(3)}\ (0) ] $$
  from
  $$H = \frac{1}2\int d^3x\ [\ \pi^2\ +\ (\nabla\phi)^2 \ +m^2\phi^2 \ ] ~? $$ 

I've been stuck in these calculations for days, any help would be greatly appreciated! 
The notes show that $\pi$ and $\phi$ are used as shown below : 
$$ \phi(x)\ = \int \frac{d^3p}{(2\pi)^3}\frac{1}{\sqrt{2\omega_p}} [a_p e^{ipx} - a_p^\dagger e^{-ipx}] $$
$$ \pi(x)\ = \int \frac{d^3p}{(2\pi)^3}\ (-i)\sqrt{\frac{\omega_p}2}\ [a_p e^{ipx} - a_p^\dagger e^{-ipx}] $$
Where p and x are 3D spacial vectors.
Also, what does this teach us about the free scalar field? Whats the underlying message other than the maths? I can't seem to understand it. I've also watched the first 5 lectures of this course (understood a good 20% of what was said).
 A: The $\pi$ is the field theory is the promotion of Heisnberg's canonical operator commutation relation in the 'ordinary' quantum mechanics.
$$[p,q]=-i$$
Define $$a \equiv \frac{1}{\sqrt{2 \omega}}(\omega q + ip)$$
And you get, using the cononical relation: $$[a, a^{\dagger}]=1$$
And the qunatum harmonic oscilator Hamiltonian is just: $$H=\omega(a^{\dagger}a+\frac{1}{2})$$
See the similiarty?
A: From your second equation, the formulae for $\phi,\,\pi$ obtain a triple-integral expression for $H$ (where I define $n$-tuple integration as over $n$ $3$-vectors). In computing the squared terms, make repeated use of $\int d^3xe^{ik\cdot x}=(2\pi)^3\delta^3(k)$ to remove the $x$ integration. These Dirac delta factors then allow you to remove one momentum integration too. I'll leave you to try it out.
As for what the maths means:

*

*the formulae for $\phi,\,\pi$ tell us the field is harmonically oscillating (the plane-wave dependence is analogous to that of a classical oscillator's position and momentum);

*your second formula for $H$ says again in analogy with classical physics that the energy has squared-momentum and squared-oscillation contributions (the $\nabla\phi$ part plays a role analogous to $\pi=\dot{\phi}$);

*and your first formula for $H$ says that each momentum contributes to the energy a per-quantum energy $\hbar\omega_p$.

In other words, these results from QFT generalise both the classical $\frac{p^2}{2m}+\frac{k}{2}x^2$ intuition and its nonrelativistic quantum extension, in which one oscillator's eigenenergies come in discrete steps.
Following @ohneVal's suggestion, I'll mention also that the quadratic formula for $H$ shows its energy is bounded below and it has a ground state, while the $a^\dagger a$-based formula adds up excitations from such number operators' eigenstates. (I alluded above to the quantum counting seen therein.)
