Preheat oven to 350°F (175°C).
If using fresh green beans, bring a large pot of salted water to a boil. Blanch green beans for 5 to 7 minutes until bright green and just tender, then drain and set aside.
In a large skillet over medium heat, melt butter and cook chopped onion until softened, about 3 to 4 minutes.
Sprinkle flour over onions and stir constantly for 1 minute to form a roux.
Gradually whisk in milk and cream (if using), stirring to prevent lumps.
Cook sauce, whisking frequently, until thickened and coats the back of a spoon, approximately 5 to 7 minutes.
Season sauce with salt, black pepper, garlic powder, and onion powder.
Add cooked green beans and sliced mushrooms to the sauce, stirring gently to combine.
Transfer the mixture to a baking dish and evenly sprinkle crispy fried onions over the top.
Optionally, sprinkle grated Parmesan or cheddar cheese before adding fried onions.
Bake in the preheated oven for 20 to 25 minutes until the sauce bubbles and onions turn golden brown.
Allow casserole to cool for a few minutes before serving warm.