The Nernst equation links the membrane potential to the free energy difference across a membrane. This is due to the disequilibrium of ions across a membrane being able to be of high energy (a larger $$\Delta\text{G}$$ value). [The equations would probably be provided in the exam; make sure to always use Volts and Joules, converting as needed]
Membrane potentials are formed when a concentration gradient of charged ions is formed, giving a difference in charge across the membrane.