Step 1: Bring 8 quarts lightly salted water in a large pot to a rolling boil over high heat. Add the macaroni and cook until al dente, about 8 minutes. Drain the macaroni in a large colander, rinse with cold water until cool, and drain again. Toss the macaroni with oil to prevent sticking.
Step 2: Set up your grill for direct grilling and preheat to high.
Step 3: Lightly brush the onion quarters and corn with melted butter (you’ll need about 2 tablespoons) and season with salt and pepper. Grill the onions and corn until nicely browned on all sides, 8 to 12 minutes in all, turning with tongs. Grill the chilies and peppers until the skins are charred on all sides, 6 to 10 minutes in all for New Mexican chilies, 16 to 20 minutes in all. Transfer the vegetables to a cutting board and let cool.
Step 4: Thinly slice the onion quarters crosswise. Cut the kernels off the corncobs. Scrape any burned skin off the poblanos and peppers and cut into 1/4-inch dice, discarding the seeds. The recipe can be prepared a day ahead to this stage.
Step 5: Brown the bacon in 1 tablespoon butter in a large saucepan over medium-high heat. Add the shallot and ham (if using) and saute until lightly browned. Stir in the onion, corn, chilies, and peppers. Stir in the flour and cook for 1 minute. Increase the heat to high and stir in the half and half. Boil the mixture for 3 minutes, stirring well: it will thicken. Remove the pan from the heat and stir in the mustard and macaroni, followed by the cheese. Add salt and pepper to taste: the mixture should be highly seasoned. Spoon the mac and cheese into the greased skillet. Sprinkle the top with bread crumbs and drizzle with the remaining 2 tablespoons melted butter. Here, too, the recipe can be prepared ahead.
Step 6: Set up your grill for indirect grilling and preheat to medium-high. If using wood chips, toss them on the coals or place in the smoker box of your gas grill.
Step 7: Place the macaroni and cheese in the center of the grill grate away from the heat. Indirect grill until the sauce is bubbly and the top is crusty and brown, 15 to 20 minutes. Serve at once.