This is a question which is frequently asked on this forum (hence the links to previous posts).
Firstly, take a guess at how much current you want through your LED. Typical values are from 10-30mA. I've used 15mA for my calculation (a reasonably conservative figure).
Next, consider the forward voltage drop across the LED. I have used 2V, another typical figure.
We'll take the 9V battery first:
Remembering Kirchoff's Voltage Law, if you have 9V across your battery terminals, and 2V across the LED, how many volts do you have across your resistor? 9V - 2V = 7V.
Now use Ohm's Law (V=IR) to determine the value of the resistor, given that V = 7 and I = 0.015. We find that R = 7/0.015 = 467 ohms. 467 is not a standard value, so I have rounded up to 470 ohms (which is standard).
For the 2AA, just use 3V instead of 9V in your equations.
LED resistor values are not terribly critical. If your value is a bit too high, then the LED will just be a bit dim. If it is too low, you will shorten the life of the LED, however, provided you keep it in reasonable limits, you shouldn't have any problems.
A bunch of assorted LED from Radioshack is bound to have very typical characteristics - no fancy super-duper-hyper-bright diodes here - around 20mA forward current, and 1.7-2.3V forward voltage drop.