You can do it like this:
Hooke's Law tells us that force
Work done = force x distance moved in the direction of the force.
With a spring we cannot use this directly since the force is constantly changing.
We need to use a bit of calculus:
This gives us the stored elastic potential energy.