Hooray, a SW question! Since I tend to get pretty wordy on these subject, i’ve got a long answer and a short answer, both based on info from the EU (which is practically but not entirely canon).
Short Answer: They run off of a standardised power cell(s). The reason given for their ability to stay working so long is that after completing their lightsaber, the creator uses the Force to “weld” everything together on an insanely small level, resulting in it having fantastic efficiency; IIRC the only time they effectively lose charge is when the blade is in contact with something.
Long Answer: They originally started off as siege weapons, and as said by other posters they used to be giant things running off of a large backpack power cell. Originally used to open doors, cut holes in things, and the like. Probably based on mining tools.
Skip a few thousand generations, and they became weapons similar to the ones in the, uhm, present. I haven’t read any explanation on how the leap was made, so pretty much all the authors copped out (and you can’t really blame them). Lightsabers can come in many forms, including the normal blades, double-sided, and short blades seen in the films. Four main parts; the case, the power cell, the focusing crystal(s), and the emitter. The crystals are what set the length, intensity, and colour of the blade, and while usually there’s a single set configuration, some lightsabers are made with alternate crystals which, when the saber hilt is twisted/some other means of swapping, can “switch out” the current blade for one of a different length/intensity/colour - useful to gain a momentary advantage in a fight with another lightsaber-wielder. Some lightsabers are made to have actual intensity-modifying controls on the outside, but that’s usually too complicated for most Jedi/Sith to bother. Power-on buttons, from seeing the films and backed up by the EU, are deadman’s switches, and so will turn the blade off on the wielder’s death. At least one lightsaber needs a double-tap to turn it on and off; this is so that it doesn’t accidentally turn on if it bashes against something problematic, say, a wall, a door, a diplomat, the wielder’s leg.
Training lightsabers are also used, where the power is dialed down to the extent that getting hit with one would just give you a nasty burn.
The reason given for the similarity shown in colours chosen (green and blue (and purple) for Jedi, red for Sith) other than it being the actual white/black hat analogue, is that the Jedi get their crystals from caves they’ve kept with for centuries; the Sith, not having access to the Jedi caves, have to make do with artificial crystals which generally make a more intense but less reliable blade. After the Jedi Purge, when knowledge of the caves was lost, Jedi had to find new crystals to use (Luke’s second lightsaber, the green one, has an artificial crystal, suggesting that the crystal-forming technology has improved but that the Sith have kept with their own tradition).