An electric dipole is a pair of charges with equal magnitude and opposite sign (a positive charge q and a negative charge -q) separated by a distance d. Consider an electric dipole placed in a uniform external electric field $\vec {E}$.
Electric dipole moment: $p = qd$.
Torque on the dipole:
$$\vec {\tau} = \vec {p} \times \vec {E}$$
$$\tau = pE \sin {\phi}$$
The torque always tends to turn $\vec {p}$ to line up with $\vec {E}$.
When a dipole changes direction in an electric field, the electric field torque does work on it.
$$\begin{align*}
dW &= -qEd \sin{\phi} d{\phi} \\
&= -pE \sin{\phi} d{\phi}
\end{align*}$$
In a finite displacement from $\phi _{1}$ to $ \phi _{2}$, the total work done:
$$\begin{align*}
W &= \int_{\phi _{1}}^{\phi _{2}} -pE \sin{\phi} \, \mathrm{d}\phi\\
&= pE \cos{\phi _{2}} – pE \cos{\phi _{1}}\\
&= -\left[ U(\phi_{2}) – U(\phi_{1}) \right]
\end{align*}$$
Potential energy for a dipole in an electric field:
$$\begin{align*}
U(\phi) &= -pE \cos {\phi}\\
&= – \vec{p} . \vec {E}
\end{align*}$$