To prepare caramelized onions: Heat olive oil in a large skillet over medium heat. Add sliced onions, 2 teaspoons thyme and season with salt and pepper. Cook, stirring occasionally, until golden, for about 10 minutes. Add wine and cook, stirring occasionally and reducing heat if necessary, until the onions are deep golden brown, for another 10 minutes. Add vinegar, increase heat to high and cook, scraping up the browned bits, until the vinegar evaporates, about 1 minute. Remove from heat and transfer to a large bowl.
To prepare stuffing: Preheat oven to 400F/ 200C. Coat a baking dish (9x13-inch) with cooking spray. Toss cubed bread with oil and pepper on a large rimmed baking sheet. Bake, stirring once, until crispy, about 15 minutes. Add to the bowl with the onions. Meanwhile, heat butter in the skillet over medium-high heat. Add celery and diced onion; cook, stirring, until the onion starts to brown, 6 to 8 minutes. Add apples, sage, thyme and salt. Reduce heat to medium and cook, stirring occasionally, until the apples start to soften, about 5 minutes. Remove from heat and transfer to the bowl with the onions and bread. Add chicken broth and gently stir until well combined. Transfer to the prepared baking dish. Cover with aluminum foil and bake for 20 minutes. Uncover and continue baking until the top is crispy, about 15 minutes more.