the energy in a spring is just the integral of the force with respect to extention, in this case that is the integral of k * x + m

= (k * x^2)/2 + (m * x)

Joe Townsend