How to keep a stable output voltage from changing input voltage
It sounds like what you need is a buck-boost converter.  These are switching voltage regulators that can produce a stable output voltage from an input voltage that is above or below the desired output voltage.  

If you want to keep things easy and just want something you can buy, Adafruit has exactly such a module.  It can accept 3V-12V in and will output 5V at somewhere between 500mA and 1000mA depending on if it is in boost or buck mode.

However, more generally, if you look for 'buck-boost' converters, you will be able to find quite a few suitable modules.