Char the Peppers: Char the 6 poblano peppers or Anaheim chiles directly over an open flame on a gas stovetop or on a baking sheet under the broiler, turning until the skins blacken and blister on all sides.
Transfer to a bowl, cover with plastic wrap or aluminum foil, and steam for 10 minutes. Peel away the skins, slice each pepper in half, and remove the seeds and chop.
Make the optional filling: Heat 2 tablespoons avocado oil in a large skillet over medium-high heat. Add 1 diced white onion and cook until starting to soften. Add the pound of ground beef, breaking it up as it cooks, then season with 1 teaspoon kosher salt. Cook until browned, about 6 to 8 minutes, then set aside.
Layer the Casserole: Preheat the oven to 350°F and position an oven rack in the center. Coat a 9 x 13-inch casserole dish with cooking spray.
Arrange half of the prepared chiles in a single layer along the bottom of the baking dish. Sprinkle with 1/2 cup shredded Monterey Jack cheese, 1/2 cup shredded pepper Jack, and 1/2 cup shredded sharp cheddar cheese. Add the cooked ground beef or beans (if using), then layer on the remaining chiles and cheese.
Make the Egg Mixture: In a large bowl, whisk together 1/3 cup all-purpose flour or gluten-free flour, 1 teaspoon salt, 1/2 teaspoon black pepper, ½ teaspoon garlic powder, ½ teaspoon chili powder, and 1/4 teaspoon cayenne pepper until combined.
Slowly whisk in 6 large eggs, one at a time, then slowly pour in the milk in a steady stream, whisking constantly until smooth.
Pour the egg mixture evenly over the layered chiles, cheese, and filling.
Bake uncovered at 350°F for 35 to 40 minutes, until the center is set and the edges is golden brown.
Let the casserole cool for 5 to 10 minutes before slicing into 12 squares with a sharp knife.
Serve: Top with sour cream, chopped cilantro, and salsa, if desired, and serve with warm corn tortillas on the side.