Formula for potential energy? Conservation of energy? How would we know what formula to use for potential energy? 
In my class, $mgh$ was used, but when dealing with a spring, it's ${1\over2}kx^2$. Is that because that's the elastic potential energy formula?
Also, for elastic and inelastic collisions, momentum is conserved. But kinetic energy is conserved only in elastic collisions, what does this really mean?
 A: One formula belongs to one type of energy. There are several types of energy. Some of them are called potential, because they are stored energies (they have a potential of being "used" again).
Let's list some energy types:


*

*Kinetic energy is associated with motion:
$$K=\frac12 mv^2$$

*Gravitational potential energy is associated with gravity:
$$U_g=mgh$$

*Elastic potential energy is associated with spring forces and elasticity in materials:
$$U_{spring}=\frac 12 kx^2$$

*Electric potential energy is associated with electric forces:
$$U_e=k_e \frac{q_1q_2}{d^2}$$

*And many more such as chemical potential energy, thermal energy, magnetic potential energy etc. 
These formulas can be used only for the specific energies they belong to. Meaning, only in the specific situations where there is spring behaviour, gravitational lifting, electric repulsion and alike. 


Also, for elastic and inelastic collisions, momentum is conserved. But kinetic energy is conserved only in elastic collisions, what does this really mean?

Actually, momentum is always conserved and energy is always conserved.


*

*In some impacts, all the energy is delivered back to the object, such as when a tennis ball hits a wall and springs back to its original shape. Or when billiard balls collide. No energy is going into deformation or significant heating or other wastes. We call all such non-wasteful collisions elastic.

*In other impacts, some energy is given away to some process during the impact. In a car crash, the car material crumbles, and that deformation takes a lot of energy. If an impact causes an explosion or a fire then much energy is converted into thermal energy. If a tennis ball hits a soft pillow, then energy is spend deforming the pillow. If a billard ball hits an edge with glue it will stop, because the adhesion force sucks out all the motion energy. In all such cases energy is not converted back into motion energy but rather used for something else. We call such wasteful collisions inelastic.


Now remember, energy and momentum is still always conserved. In inelastic cases you just must be aware that the energy is no longer in the objects as motion energy. It is somewhere else. You can't know how much was wasted to somewhere else. So the energy conservation law is useless for inelastic collisions. It still holds true, as it always does, it just doesn't help us in those cases. 
A: For conservative forces the Potential energy can be defined as $$U=-\int_{x_i}^{x_f} \vec{F} d\vec{x}$$ For example think about $$\vec{F}=mg(-\vec{i})$$
I put a minus sign because it means that I choosed upward direction as positive. If we put the equation we have
$$U = -\int_{x_i}^{x_f} mg(-\vec{i})dx\vec{i} = mg(x_f-x_i)$$ which it means that if you move the object upper the potential energy of the ball will increase since $x_f>x_i$
For the spring case its the same idea. Maybe even you can try it. We know that $$\vec{F}=-kx(\vec{i})$$ (Lets assume motion happens in $i$ direction)
If you put it into the Potential energy equation you'll see that its equal to $1/2kx^2$
For the second part of your question. In inelastic conditions we assume that some of the energy goes to heat and internal energy that merges the two particles.That is why energy is not conserved. 
A: For the first part, you have to remember the work done by a spring. Say we have a coil spring squeezed by amount of x cm and locked in this position, hence loaded with a force of F= kx.
But when you release the lock and allow the spring to stretch back to its relaxed length, F gradually tapers off to zero. 
So the work done by spring is average of F and 0, or
$ (kx+0)/2 (x) = \frac {1}{2}kx^2$
As for the second part of your question, in an inelastic collision the total moment is conserved, but the kinetic energy is partially lost to vibration of parts  after impact which is turned to heat and plastic deformation of them.
A: Both equations for potential energy are of the form $\text{force}\times \text{distance}$ ie $mg \times h$ and $kx \times x$.
The factor $\frac 12$ is there for the spring potential energy because the force does not stay constant as the extension of the spring changes unlike the gravitational force on a mass which stays constant as its height changes.
So for the spring one averages the force $\frac{mg}{2}$ to get the potential energy.   
—-
The momentum of a system is conserved if there are no external forces acting on a system.
The energy of a system is conserved in such a case but there may be an interchange between differing forms of energy.
In particular the kinetic energy can:  


*

*decrease which is called an inelastic collision with the kinetic energy being converted into heat, light and work being done in permanent deformation. 

*stay the same which is called an elastic collision during which there may be deformation but any elastic potential energy stored is then converted back to kinetic energy. 

*increase which is called a super elastic collision during which the kinetic energy of the system actually increase. An example being an explosion during which chemical energy is converted into kinetic energy.

