2½ pounds green beans, trimmed and cut into 1- to 2-inch pieces (about 8 cups)
2-3 tablespoons extra-virgin olive oil, divided
1 medium onion, thinly sliced
3 tablespoons all-purpose flour
¾ teaspoon salt
¼ teaspoon white or black pepper
2½ cups low-fat milk
1½ cups fresh whole-wheat breadcrumbs (see Tips) or ½ cup shredded or crumbled cheese
Position racks in upper and lower third of oven; preheat to 425°F.
Toss green beans in a large bowl with 1 tablespoon oil until well coated. Divide between 2 baking sheets and spread in an even layer. Roast, stirring once and rotating the pans top to bottom about halfway through, until tender and beginning to brown, 20 to 25 minutes.
Meanwhile, heat 1 tablespoon oil in a large saucepan over medium heat. Add onion and cook, stirring frequently, until very soft and golden brown, 5 to 8 minutes. Add flour, salt and pepper; cook, stirring, for 1 minute more. Add milk and continue to stir, scraping up any browned bits. Cook, stirring, until the sauce bubbles and thickens enough to coat the back of a spoon, about 4 minutes. Remove from the heat.
When the green beans are done, remove from the oven. Preheat the broiler.
Transfer half the green beans to a 2-quart, broiler-safe baking dish. Spread half the sauce over the green beans. Add the remaining green beans and top with the remaining sauce.
Combine breadcrumbs and the remaining 1 tablespoon oil in a small bowl (skip this step if you are topping with cheese).
Sprinkle the breadcrumb mixture (or cheese) over the gratin. Place under the broiler and broil, watching closely, until the gratin is bubbling and beginning to brown on top, 1 to 5 minutes, depending on your broiler. Let stand for 10 minutes before serving.