A casserole will keep in the refrigerator for up to 4 days before it starts to grow bacteria and go bad.
You can keep the casserole longer than 4 days if you freeze the casserole in a freezer safe container.
I've kept casserole in the freezer for up to a year before even though it lost it's freshness after a year in the freezer the casserole was still very safe to eat.
After cooking the casserole it should be either eaten or refrigerated within 2 hours to prevent the growth of bacteria.
After 2 hours at room temperature bacteria will start growing on the casserole or other food so make sure you either refrigerate any leftovers including the casserole or freeze it to keep it longer.