In a skillet over medium heat, melt 1 tablespoon butter and cook sliced onions with a pinch of salt until caramelized, about 15 minutes, then set aside.
Mix chilled mac and cheese with beaten egg and panko breadcrumbs, then form into 4 patties about 1/2-inch thick.
Heat vegetable oil in a large skillet over medium-high heat and cook patties for 3-4 minutes per side until golden and crispy, then set aside.
Spread mayonnaise on one side of each bread slice.
Assemble sandwiches with mayo-side out: bread, Swiss cheese, mac and cheese patty, caramelized onions, another slice of Swiss, and top bread slice.
Melt remaining butter in the skillet over medium heat and cook sandwiches for 3-4 minutes per side until golden brown and cheese is melted.
Cut in half and serve immediately while hot and crispy.