Like everything else in the world, picking a new water heater requires an unreasonable amount of research and nail biting. Here's a taste, based on a friend of mine's situation. It should be pretty easy to plug in your own numbers for usage and utility rates to do this for yourself.
Some terms:
Sorry for the units, all you socialist users of the metric system!
BTU: the amount of energy it takes to heat one pound of water 1˚F (aka British Thermal Unit)
1 kWh = 3412.3 BTU (common unit for selling electricity)
1 therm = 100k BTU (common unit for selling natural gas)
1 gallon of water weighs 8.35 lbs.
EF: efficiency rating - tells you how much incoming energy makes it into the hot water. Manufacturers like to bs around with this. For example, I believe they ignore any electrical consumption made by a gas appliance.
First, estimate your usage. For my friend, I figure one shower a day (10 min @ 2.5 gpm @ 105˚F) uses about 20 gal of hot water (the rest of the 25 gallons used is cold water mixed in the shower valve). 1 load of laundry average per day = 4 gal in her high efficiency front loader. Dishes, hand washing, etc. takes another 10 gal. So, 30 gallons a day.
How much energy is that? The average incoming cold water is about 50˚F here. If the tank is set to 120˚F, that's an increase of 70˚F, and that 30 gallons weighs 250.5 lbs. 70 x 250.5 = 17535 BTU per day.
Electric
The most basic electric water heater has an efficiency rating of about 0.90, and putting a thicker layer (3") of foam insulation gets them up to 0.95 pretty quick and cheaply. Note that the EPA no longer gives Energy Star certifications to any electric tank models except for the heat pump hybrids. The bottom line is it's too easy to get right close to the theoretical maximum EF of 1.0, so they don't feel like they need to reward anyone for that. Given how many people and programs base their buying on the Energy Star label, I think that's a mistake, but anyway... So, I'm looking at a 40 gallon model with a 12 yr warranty at Lowe's for $450. Nothing fancy. At EF 0.95, this model will consume 1974 kWh per year. (17535 BTU / 0.95 = 18458 BTU input needed per day... 18458 / 3412.3 = 5.41 kWh / day... 5.41 x 365 = 1974 kWh / yr). Our electricity is 0.11 per kWh, so operating cost is estimated at $217 a year.
Natural Gas
A very basic gas water heater is only about EF 0.59, but it's easy to find them up around 0.64. Energy Star models have to exceed 0.67, and the highest efficiency models get up to 0.70. I'm looking at a 0.67 Energy Star, 12 yr warranty model at Lowe's for $570. This model will consume 95.5 therms of natural gas per year. (17535 / 0.67 = 26172 BTU input per day... 26172 x 365 = 9,552,649 BTU / yr... divided by 100k = 95.5 therms / yr) Our natural gas is $1.08 per therm, so operating cost is estimated at $103 a year.
So even though the gas unit costs more, it should pay for itself pretty quickly, and the savings is more if you use more than the fairly minimal amounts in the examples above. But of course there are other things to think about. All-new installation of a gas unit can be very expensive. It needs an exhaust vent (chimney), or for some models they can vent via a plastic pipe out through the wall. Gas units are dependent on both the electricity (fans, controls, igniter) and gas utilities to operate. Electric just needs electricity. Electric units have no moving parts, and are much less complicated. They also are very cheap to repair (replace an element or thermostat) and the little bit of energy that they do lose ends up in your house. We live in a coolish climate, so the extra heat is a good thing for eight months of the year. Gas units dump all their excess energy out the vent, and they also poke another hole in your house's building envelope, requiring installation of a motorized vent damper if you don't want air flowing through the stack when the unit isn't operating. Electric heaters are much less likely to cause explosions if you happen to spill something flammable near them, and the carbon monoxide hazard is zero.