For non rechargeables, buy quality cells then cycle them out regularly. Modern alkaline cells have a minimum storage life of over ten years. Avoid high heat, and avoid storing them in the fridge. Room temperature is perfectly fine.
Depends on the chemistry. Generally lithium stores better than NiCd or NiMH. Those can have storage lives as little as 2-3 years even with periodic charging.