Preheat the oven to 350°F.
Heat the butter in a large, deep skillet over medium heat. Add the diced onion and sauté until soft and translucent, about 4 to 5 minutes.
Add the salt, pepper, mushrooms, and garlic. Sauté until the mushrooms have released their water, about 5 minutes.
Sprinkle the flour over the top and stir well until no visible white flour remains.
Slowly pour in the milk while whisking continuously to prevent clumping.
Increase the heat to bring to a boil, then reduce the heat to medium-low and simmer 5 to 7 minutes, until thickened.
Whisk in the nutritional yeast and miso paste, if using, until smooth.
Add the green beans and stir well to coat.
Transfer the mixture to the casserole dish. Sprinkle the fried onions evenly over the top.
Bake for 15 to 20 minutes until the top is golden and the middle is hot and bubbly.