Cook the onion. Slice the onion into thin half-moons. Heat the olive oil in a cast iron or oven-safe pan over medium heat. Add the onion and cook until it starts to soften and turn translucent.
Add the garlic and herbs. Stir in the garlic, thyme, oregano, parsley, and crushed red pepper flakes. Cook for another minute or so, just until the garlic becomes fragrant.
Make the tomato sauce. Add the crushed tomatoes and salt. Stir everything together and cook for about 5 minutes, until the sauce is bubbling.
Add the beans. Stir in the butter beans and reduce the heat to medium-low. Let everything simmer for about 15 minutes, stirring occasionally.
Add the cheese. Preheat the oven to 400°F (200°C). Remove the pan from the heat and sprinkle the mozzarella and Parmesan evenly over the top.
Bake until bubbly. Place the pan in the oven and bake for 12–15 minutes, until the cheese is melted, bubbly, and lightly browned. For extra browning, turn on the broiler for the last 3–5 minutes, keeping a close eye on it.
Garnish and serve. Carefully remove the pan from the oven and sprinkle with fresh basil. Serve immediately with toasted or grilled bread, or spoon the beans over polenta.