Energy formula electric field

I am currently reading through my electrodynamics lecture notes and I can't understand a calculation.

$$E = \frac{1}{2} \int \mathrm{d}^3x \, \phi(\mathbf{x}) \rho(\mathbf{x}) = - \frac{\epsilon_0}{8\pi} \int \mathrm{d}^3x \, \phi(\mathbf{x}) \Delta \phi(\mathbf{x}) \\ = \frac{\epsilon_0}{8\pi} \int \mathrm{d}^3x \, \nabla \phi(\mathbf{x}) \nabla \phi(\mathbf{x}) = \frac{1}{8\pi} \int \mathrm{d}^3x \, \mathbf{D} \cdot \mathbf{E}$$

I know the identity $\nabla ( f \nabla g) = \nabla f \cdot \nabla g + f \Delta g$ which I could easily prove by looking at the components and summing. I think I have to use this identity from the first to second line in the above equation but I don't know why $\int \mathrm{d}^3x \, \nabla (\phi \nabla \phi) = 0$. I tried using $\nabla \phi = -\mathbf{E}$ and the divergence theorem but I couldn't show that.

The question is pretty specific and you don't get much insight from it but I would really like some help.

$$\int_{\mathbb R^3} d^3 \mathbf x \boldsymbol\nabla . \big(\phi(\mathbf x) \boldsymbol \nabla \phi(\mathbf x)\big) = \oint_{\partial {\mathbb R^3}} d \mathbf a \ .\phi(\mathbf x) \boldsymbol \nabla \phi(\mathbf x)$$ Now if your integral is over all space, which it is, the boundary is "at infinity". The potential goes to zero at infinity; making the right boundary integral go to zero. Thus, $$\int_{\mathbb R^3} d^3 \mathbf x \boldsymbol\nabla . \big(\phi(\mathbf x) \boldsymbol \nabla \phi(\mathbf x)\big)=0$$