$$\require{cancel}$$
Refer again to Figure III.3. There is a torque on the dipole of magnitude $$pE \sin θ$$. In order to increase $$θ \text{ by }δθ$$ you would have to do an amount of work $$pE \sin θ\, δθ$$ . The amount of work you would have to do to increase the angle between $$\textbf{p} \text{ and }\textbf{E}$$ from 0 to $$θ$$ would be the integral of this from 0 to $$θ$$, which is $$pE(1 − \cos θ)$$, and this is the potential energy of the dipole, provided one takes the potential energy to be zero when $$\textbf{p} \text{ and }\textbf{E}$$ are parallel. In many applications, writers find it convenient to take the potential energy (P.E.) to be zero when $$\textbf{p} \text{ and }\textbf{E}$$ perpendicular. In that case, the potential energy is
$\text{P.E}=-pE\cos \theta = -\textbf{p}\cdot \textbf{E}.\label{3.4.1}$
This is negative when $$θ$$ is acute and positive when $$θ$$ is obtuse. You should verify that the product of $$p \text{ and }E$$ does have the dimensions of energy.