I’m probabla way the f… off base, but I’ve always considered it to be similar to the way a capacitor works.
A capacitor stores energy by distorting the electrical fields in the conducting plates. From what I’ve read/seen as diagrams, this equates to distorting the orbits of the electrons. Charge the plate, push the electron orbits out of whack. When you discharge the plates, the orbits snap back to normal by shedding the energy pushed into them by the charging process.
For magnets, I imagine something similar. A magnet by itself has no force or charge to exert. Then I coma along with a second magnet and push it against the field of the first magnet. This distorts the magnetic fields of both magnets, in effect charging them with potential energy. Now, I release the second magnet, and the distorted magnetic fields attempt to return to normal by shedding the energy that I put into the system by forcing them together.
Think of it maybe this way:
I’ve got a ton of lead sitting on the Earth’s surface. Compared to the Earth’s surface, that lead has a potential energy of zero. This is like the two magnets being separated by a large distance.
Now I use a crane and lift that block of lead fifty feet up from the ground. The lead now has potential energy that can be used to do work (smash somebody flat if he’s dumb enough to get under it.) This is like forcing the two magnets together. Forcing them together takes work, which puts energy into the system.
Now I cut the cable holding the lead. The potential energy (that I’ve stored in the system) becomes kinetic energy and the lead moves, accelerates, smashes into the ground and generates heat. Similarly, I can release the magnets and allow the potential energy to become kinetic energy and the magnets move away from one another.
The only energy involved is that which is used to force the two magnets together. A magent loses its effectiveness when the particles (the smaller mganets it is composed of) lose their alignment. Forcing two magnets to stay together may cause the alignment to be lost sooner.
Magnetism is an inherent property of the material, like gravitational attraction, and can’t really go away. Since magnetism is bipolar (unlike gravity, which is monopolar,) alignment is critical and can reduce the apparent strength even though the total magnetism of an object stays the same.
So. That’s my understanding of it.
Take it with a big grain of salt, since I’m not a physicist and my last physics class was like 16 years ago.