Derivation of the maximum entropy distribution

$\int_0^\infty \mathrm e^{-a x} \mathrm d x = \frac{1}{a}$ for $a>0$.

$\int_0^\infty x \mathrm e^{-a x} \mathrm d x$ may be evaluated by integration by parts.


Your question about the infinite integrals has already been answered (note that you can make your life easier by absorbing the $1$ into $\lambda_1$), so I'll just answer your question about how to systematically optimize such an integral. The general theory for this sort of thing is the calculus of variations, the main result of which is the Euler-Lagrange equation. However, since your integral depends only on $p$ and not on the derivative of $p$, the Euler-Lagrange equation just reduces to $\frac{\partial \mathcal L}{\partial p}=0$ (where $\mathcal L$ is the Lagrangian density, i.e. the integrand), so your calculation is correct.