A body of mass M is attached to the lower end of a metal wire, whose upper end is fixed. The elongation of this wire is l.
Loss in gravitational potential energy of M is Mgl
The elastic potential energy stored in the wire is Mgl.
v=12×stress×strain×volume
= 12×MgA×lL×AL
= 12Mgl
And we know change in gravitational potential energy will be Mgl.