$A \cup B$ and $A \cap B$ connected $\implies A$ and $B$ are connected

Let $X=A\cup B$. Suppose $A$ is disconnected. In particular, $A=C\cup D$ a separation, where $C,D\subset A$ are closed. Thus, they are closed in $X$. Now, consider $A\cap B\subset A$. By a common theorem taught in topology courses, we know $A\cap B\subset C$ or $A\cap B\subset D$, but not both. If $A\cap B\subset C$, then $B\cap D=\emptyset$, so $(B\cup C)\cup D=X$ is a separation. If $A\cap B\subset D$, then $B\cap C=\emptyset$ and $(B\cup D)\cup C=X$ is a separation. Contradiction. So $A$ must be connected.

Hope that helps.

Edit: Suppose $A\cap B\subset C$. Let $x\in B\cap D\subset B\cap A$ since $D\subset A$. But $x\in B\cap A\subset C$ by supposition. But $x\in B\cap D\subset D$. So $x\in C\cap D=\emptyset$ since this is a separation. Contradiction. So $B\cap D=\emptyset$. The other case is equivalent.