We know that when the mass is suspended, the spring stretches by l, then Mg=kl. And energy stored in spring = kl2/2 = (kl)l/2 = Mgl/2.
When the spring oscillates at the maximum displacement, additional potential energy stored = kl2/2 = Mgl/2.
Therefore maximum potential energy or total potential energy = Mgl/2+Mgl/2 = Mgl