It depends on the type of formula, but you should never refrigerate formula that has been heated or partially consumed!
It is okay to prepare baby formula ahead of time and keep it in the refrigerator for up to 24 hours for powdered versions or up to 48 hours for ready-to-drink formulas. However, after a bottle has been heated, it needs to be consumed or thrown away after an hour. You cannot put it back into the fridge once it has been heated! At room temperature, the formula can sit for two hours before it should be discarded but only if your infant has not started the bottle. After bottles have been started, they should not be saved.