Heat oven to 375 degrees.
Oil or butter a 2-quart baking dish or gratin dish.
Drain off about 1/2 cup of liquid from beans, retaining it in a separate bowl to use later for moistening beans, should they dry out. Heat oil over medium-high heat in a large, heavy nonstick frying pan and add ground cumin and chili.
Cook, stirring over medium heat, for about a minute, until the spices begin to sizzle and cook. Add beans and optional chipotle.
Fry beans, stirring and mashing with the back of a spoon, until they thicken and form a thin crust on the bottom of the pan. Stir up crust and mix into the beans.
Cook until beans are thick but not dry, about 10 minutes.Add liquid you saved from the beans if they seem too dry. Taste refried beans and adjust salt (they probably won't need any as the broth reduces when you refry them).
Spread in an even layer in the baking dish. (Note: If you use canned beans, do not drain. The frying process will go more quickly.)
Clean and dry skillet. Heat over medium heat and add olive oil. Add onion and cook, stirring, until tender, about 5 minutes. Add a pinch of salt and garlic and cook, stirring, until garlic is fragrant, about 30 seconds.
Add squash, oregano, salt and pepper, and turn up heat slightly. Cook, stirring often or tossing in pan, until squash is translucent and tender, 5 to 10 minutes. Taste and adjust seasoning.
Spread in an even layer over the beans.
Combine corn and milk in a saucepan and bring to a simmer. Simmer 5 minutes, until corn is just tender. Stir in cornmeal and minced serrano, add salt to taste, and continue to simmer until mixture is thick, 3 to 5 minutes.
Stir in grated cheese. Remove from heat and spread in an even layer over squash. Sprinkle crumbled cheese over top. Dot with butter or drizzle on oil.Place in oven and bake 25 minutes, until bubbly and crumbled cheese is lightly browned. Serve hot or warm.