Given the energy integral: $E(u) = \frac{1}{2}\int_V (e_t^2) dV$
$e_t = \nabla \cdot(D \nabla e)$
Differentiating this integral w.r.t. time yields the below: $ \frac{dE}{dt} = \int_V ee_t dV = \int_V e \nabla \cdot(D\nabla e) dV = \int_V \nabla \cdot(e D\nabla e) dV - \int_V \nabla e \cdot( D\nabla e) dV $
I don't understand the relation on both sides of the last equal sign on the last line: in other words how does the following general relation hold: $p \nabla ^2 p = \nabla (p \nabla p) - (\nabla p)^2$
The last equal sign is just the product rule, we have $$ \def\div{\mathop{\rm div}}\def\grad{\mathop{\rm grad}}\div (eD\grad e) = e \div(D\grad e) + \grad e \cdot D\grad e $$ hence $$ e\div(D \grad e) = \div(eD\grad e) - \grad e \cdot D \grad e $$
Addendum: For the simplified version with $p$, it's the same, we have $$ \div(p \grad p) = \grad p \cdot \grad p + p \div\grad p \iff p \div\grad p = \div(p\grad p) - \grad p \cdot \grad p $$