In a large pot or Dutch oven, heat the butter and olive oil over medium heat.
Add the sliced onions, sugar, and salt, and stir. Cook, stirring occasionally, for about 30 minutes, until the onions are caramelized and a deep golden brown.
Add the white wine (if using) to deglaze the pot, scraping any browned bits from the bottom. Let it simmer for 5 minutes.
Pour in the beef broth, add thyme and bay leaf, and bring the soup to a boil. Reduce the heat and let it simmer for an additional 10 minutes.
While the soup simmers, preheat your oven to 400°F (200°C).
Toast the slices of baguette in the oven until golden brown, about 5-7 minutes.
Remove the bay leaf from the soup and ladle the soup into oven-safe bowls. Top each bowl with a slice of toasted baguette and a generous amount of grated Gruyère cheese.
Place the bowls on a baking sheet and bake in the oven for about 10 minutes, or until the cheese is bubbling and golden brown.
Carefully remove from the oven, let cool slightly, and serve hot with a sprinkle of freshly ground black pepper.