When backpacking, I might carry a MagLite flashlight or something similar that requires two AA batteries. I tend to favor rechargeable batteries for a variety of reasons.
How can I recharge my batteries in the wilderness?
Perhaps the most obvious and commercially available is solar, which has options ranging from small pocket-sized chargers to roll-out military grade flexible panels. I believe Brunton makes a consumer grade version of the latter (not as bullet-proof), and iGo has some nice versions of the former.
I have used both with some success, the panel is probably over-kill if you are just looking to charge a few AAs (we were charging GPS dataloggers and hand-held computers). However, the small ones are not something I would depend upon, tending to charge slowly. Both require (of course) sunlight.
The second option is to carry more batteries -- either another set or two of fully charged batteries in the size you need, or if you have a variety of other electronics to charge, an old-school camcorder battery can be used to re-charge smaller batteries. Some companies make recharge-able power-packs geared toward cell-phones which function the same way.
However, for anything critical (emergency devices) I would highly recommend ALWAYS packing a set of fresh, regular batteries that you can slip in when your re-charge options fail.
Digression 1: I've often thought a little hydro-generator would be slick if you are camping near a creek - plop it in the current and charge overnight... but have yet to find one (or hear of a do-it-yourself) that is practical.
Digression 2: While poking around for the hydro-power, I found this wind turbine which looks like a fun project... and possible could (should) be modified for water-born deployment. Water always flows.
BONUS PRO-TIP: On cold mornings, gently warming a dying battery (ie in your arm-pit, or in a hot cup of coffee) can sometimes get the reaction going just enough to generate a last gasp of energy. Highly NOT recommended as standard practice due to explosion concerns, but in a life-or-death emergency, it might give you enough juice to make that critical radio call.
Apart from the often mentioned possibility of bringing enough batteries or buying new ones along the way, I would like to list possibilities for recharging.
As already mentioned by @LBell, there are the following two:
Apart from these, I would like to add some.
Things to look out for
Electronic devices look for very different voltages and powers. Make sure, the charger you´re about to buy fits the thing you want to charge or ask the manufacturer if its supported. Rule of thumb: The voltage the charger can supply needs to be higher than your devices input voltage (somewhere around 4-5V for USB-charging, or around 1.5V per AA-Battery), and the higher the power the faster the charging.
I've tried very hard to keep a charge on a smart phone while on backpacking trips. It was used primarily for recording GPS routes and photos to look at later rather than for anything important. I tried one of these Powerfilm AA Chargers on my pack and it worked very well for charging AA batteries, but didn't get enough power for the smart phone. For medium-length trips (1-2 weeks-ish), you'll probably get more power with less weight and less cost by just carrying extra batteries. Beyond that, solar seems like it might weigh less if you don't draw too much power. Possibly some form of hand crank as an alternative.
Probably as expected, advice varies wildly depending on whether you're talking about relying on charging the batteries for a life / death situation or it'd just be a "nice to have" if such an option was available.
If it's for emergency purposes then just bring a spare set of batteries - or more specifically, one more set than you calculate you'll ever need. These can be rechargeable as well, but if they are make sure they're relatively new and still hold their charge well (this is especially important because in cold temps rechargeables that are a bit worn out can sometimes fail completely. I've had it happen a couple of times!)
Another option is to take a wind up torch - ok so it's not specifically recharging any old batteries, but it does provide you with a source of power limited only by how much you're willing to turn the thing. They're not that expensive these days either - I remember when they first came out and they cost hundreds... anyway...
In terms of actually constructing a recharging station, the simple way would be to purchase a solar powered battery charger such as this one (I'm aware you can't actually buy it from there anymore but you can see the type I mean!) You could also make something yourself out of solar panels - and equally potentially make something to work with the wind or flowing water.
Unless you're just doing it for fun though I'd be tempted to say don't bother - the size of those contraptions is generally much more than several sets of even D cell batteries, let alone AA, so unless you really don't trust batteries to stay charged or you really rely on going through a heck of a lot of batteries, it's still probably not the most practical option.