For a magnetic dipole placed in a uniform magnetic field, the torque is given by τ=M×B, and potential energy U is given as,
U=−M⋅B=−MBcosθ
When M is in the same direction as B then τ=0 and U is minimum = −MB as θ=0o.⇒ Stable equilibrium is (b).
When M the opposite direction of B, then τ=0 and U is max = +MB
As, θ=180o ⇒Unstable equilibrium in (d)
(b) 
(d) 