We can define the potential energy of an object within a conservative force field (gravitational,elastic, electromagnetic forces).
To calculate the difference of potential energy of an object, between two positions, we'll have to determine the work nedeed for the object to move between these positions. Once we know the value of the work done, the potential energy is the negative of this value.
In the gravitational field of forces, the potential energy is:
PE = m*g*h
m is the mass of the object
g is the gravitational acceleration = 9.8[m/s^2] approx.
h is the height measured from the surface of the Earth to the position of the object whose potential energy has to be found out.
If we want to determine the potential energy of a spring, we'll have the formula:
PE = k*x^2/2
k is the spring constant
x is the displacement of the spring with respect to the equilibrium position.