Preheat oven to 275 degrees. Heat oil in a small Dutch oven or other heavy 3-quart pot over medium-high heat. Add shallots and onions, tossing to coat, then bring to a simmer. Add tomatoes, oregano, rosemary, 1 tablespoon salt, and a pinch of red-pepper flakes. Cover, and transfer to oven.
Bake until onions are very tender, about 2 1/4 hours. Uncover, and bake until onions are slightly golden around edges, about 15 minutes more. Stir in vinegar, and let shallots and onions cool slightly in oil. Before serving, discard herb sprigs. Serve warm or at room temperature.
Shallots and onions in oil can be refrigerated, covered, up to 2 weeks. Bring to room temperature before using.