The force experienced by the charges is given as qE and+qE , as can be seen in the figure.
τ=→p×→E
The amount of work done by the external torque
W=∫θ1θ0τsxt(θ)dθ=∫θ1θ0pEsinθdθ =pE(cosθ0−cosθ1)
As we know that the work done in bringing a system of charges from infinity to the given configuration is defined as the potential energy of the system.
The potential energy U(θ)
U(θ)=pE(cosθ0−cosθ1)