Sorcery-speed spells (sorceries, and other spells/abilities restricted to sorcery speed) can only be cast when you have priority, it is your main phase, and the stack is empty. This is codified in CR 307.1, which states a sorcery can be cast only when the stack is empty during a main phase on your turn.
The question contains a contradiction: if an opponent's instant is on the stack, the stack is not empty. A spell or ability remains on the stack until it resolves, is countered, or otherwise leaves the stack (CR 405.1, CR 608.2). Priority passes back and forth between players while objects are on the stack, but those objects stay there until resolution.
Once you cast an instant or it is otherwise put on the stack, both players get opportunities to respond (CR 117.3b), but the stack is occupied the entire time. The active player does not get sorcery-speed privileges just because it is their main phase if even one object sits on the stack.
Example: It is your main phase and you cast Lightning Bolt targeting a creature. Before it resolves, your opponent casts Counterspell targeting your Lightning Bolt. Now the stack has two spells. You receive priority again, but you cannot cast Divination (a sorcery) right now — the stack is not empty. You must either pass priority or cast another instant-speed spell.
In short, the stack being empty is a strict prerequisite for sorcery-speed casting (CR 307.1). An opponent's spell sitting on the stack, regardless of whose turn it is or what phase you are in, means the stack is occupied and sorcery-speed restrictions apply.
Unofficial fan resource — not affiliated with or endorsed by Wizards of the Coast. Answers are AI-generated estimates grounded in the Comprehensive Rules and are not a substitute for an official judge. Verify anything match-critical.