Carl, you are mixing energy, work, and forces.
Pure energy doesn't exist in our world, it has to take some physical form like kinetic energy (speed) heat or mass for example.
All forces involve energy in some way.
Holding an object in the air against gravity requires energy.
Gravity is caused by mass (a form of energy), but the actual cause and effect phenomenon that ties particles mass and gravity is still unknown.
Physicists around the globe are working on it, and the LHC (large hadron collider) : the largest particle accelerator which has just been built in geneva at CERN is trying to adress this issue.
What you mixed up with is work.
Work is the effective energy used to do something.
If you're holding something still in the air against gravity then you are producing no work but you are still consuming energy to maintain this object in the air.
Moving this object in any direction requires work.
Work is provided by you if you move the object horizontally, and is provided by you and gravity at the same time if you move it vertically.
Potential energy is the equivalent amount of energy that gravity would require to bring an object from point A to point B and if there was no other forces involved. It is calculated as the opposite of the work of gravity. But the actual amount of energy required by gravity to move an object from point A to point B is different since there are other parameters that may interfere like air resistance, or some stupid guy holding this object in mid-air
![Wink ;)](./images/smilies/icon_e_wink.gif)
The actual energy is usually higher but it can also be lower if you use your own force to help gravity : for instance if you throw the object downwards.
Magnets are better known than gravity but more complex since calculating a magnetic force requires knowing many advanced physics phenomenons involving electricity, electric fiels, magnetic fields and if you want to follow the whole energy pattern you also need to know quantum physics, which make fewer people know how they actually work. (i reassure you, i am totally unable to do it but i'm gonna give you the big lines)
The magnetic field is created by electric currents inside the magnet.
In a ferromagnet material (magnet stone) the electrons can jump from one atom to an other almost freely (like in all conductive materials). But ferromagnets have a special feature in it's internal structure that makes the electrons follow certain patterns. When an electron moves it creates a very tiny magnetic field around its movement. There are millions of different patterns in every possible direction inside a single magnet stone but it creates an average magnetic field.
If this average magnetic field is strong enough to be noticeable (a lot of patterns go in the same directon), then the ferromagnet material becomes a magnet.
You can also create a magnet by manually creating an electric current. Any electric current passing through an electric cable creates a small magnetic field around the cable. But it is usually way too weak to have any visible effect. In order to increase significantly the strength of this magnetic field : the simplest way to go is to roll your electric cable many many many times in circle, turning always in the same direction and make a coil.
Make a continuous direct current circulate through the coil and you get a strong enough magnetic fields inside the coil to get visible effects and you get an electromagnet.
Magnets use energy : electromagnets require you to provide electricity, in ferromagnets the energy comes from the natural motion of the electrons inside the material which is naturally maintained by a lot of physics phenomenons like heat, molecule electric interactions and the many quantum physics stuff that happen at the atom scale : but i don't know enough to tell you anything about these.
But remember that it does consumes energy to maintain the magnetic field of a magnet : the simplest example i can give you is tha tyif you put two magnets against each other, they progressively loose their magnetic force over time.
As far as where the energy comes from : it's there since the big bang and it's dissipating progressively over time.
It's going down, nature has many tricks to reuse energy so it's going slowly but the ultimate fate of the universe is to run out of energy... unless something happens that makes the universe crunchs on itself but we won't know that for a few billion years.