If elastic potential energy (lets call it U) is the only energy involved, then W = - U. Remember, in using Hookes law, that if W = force times distance, the spring force is not constant, so you need to use calculus to find the work, or simply note that the spring force varies from 0 to its max value of kx.
If the initial force in the spring is 0, and the force varies linearly with x (F=kx) as it is stretched, then at its maximum point of stretch , the force is F=kx, where x is at its maximum. So the average force during that period of stretch is just (0 + kx)/2, or F_average =kx/2. Now use that value of force in your work equation to find the work done by the spring.
On the graph of F vs. x, the potential energy is equal to the area under the curve between 0 and x. What constant force would have the same area underneath?