Drain the sauerkraut in a colander. Rinse with water if you prefer it less acidic.
Peel the onions and cut into cubes. Dice the bacon into small pieces.
Heat a large pan over medium-high heat. Add the diced bacon and cook for 2-3 minutes until the fat is rendered. Add the onion cubes and cook for 2 minutes. Add the minced beef and cook for 5-7 minutes, stirring frequently, until browned and crumbly. Season with salt and pepper. Stir in the tomato paste and cook for 1 minute. Pour in the red wine, scraping up the browned bits. Add a strong pinch each of thyme and oregano. Bring to a boil and simmer for 1-2 minutes.
Prepare the mashed potatoes.
Grease a baking dish with the margarine. Spread half the minced beef mixture on the bottom. Layer the drained sauerkraut on top. Spread the remaining minced beef mixture over the sauerkraut. Spread the mashed potatoes in a thin layer on top. Sprinkle with the grated Gouda or Emmentaler cheese. Dot the surface with butter flakes.
Bake in the oven at 200°C (392°F) for 35-45 minutes until the cheese is golden brown.
To reheat leftovers: Place a serving on a covered plate, drizzle with 1 tablespoon water, add a small amount of butter or margarine. Heat in the microwave at 600 watts for 3-4 minutes until heated through.