It's great that you asked about the earth and an electron because they have completely different answers.
For the earth, the origins of the spinning are similar to the origins of the spinning and orbiting energies of all sorts of stars, planets, galaxies, etc. Start with a collection of matter spread more or less uniformly through space. It can lower its gravitational potential energy by clumping up, since things attract gravitationally. That lost potential energy goes into various other forms, including kinetic energies of spins. Why do things spin? The clumping is triggered by little non-uniformities in the starting distribution. As stuff starts to clump up, the neighboring stuff is also a little non-uniform, producing some forces and torques between different clumps. In general, a collapsing clump will have a little angular momentum, because it would take a special accident for it to have exactly zero. So the energy comes from the lost gravitational potential and the angular momenta of the different parts comes from the same sort of accidents that allow clumps to form.
Electrons are a fundamental type of particle, at least so far as our current understanding goes. This particular type of particle, like many others, has a fixed intrinsic
angular momentum. There simply isn't such a thing as a non-spinning electron. All electrons have exactly the same magnitude of spin, although obviously the average orientation can point any direction. Any energy associated with that spin cannot be distinguished from the total rest-energy of an electron, the minimum energy required for any electron to exist, i.e. the rest mass times c2
(published on 02/16/11)