Let $A$ and $B$ be $n \times n$ real matrices such that $AB=BA=0$ and $A+B$ is invertible
First $AB=0$ means $\mbox{Im}B\subseteq \mbox{Ker}A$, hence $\mbox{rank}B\leq \mbox{null} A=n-\mbox{rank} A$. Now $\mathbb{R}^n=\mbox{Im}(A+B)\subseteq \mbox{Im}A+\mbox{Im}B$, hence $n\leq \mbox{rank}A+\mbox{rank}B\leq \mbox{rank}A+n-\mbox{rank} A=n$. So $\mbox{rank}A+\mbox{rank}B=n$.
Rank-nullity theorem on $A$ and on $B$.
Observe that $(A-B)^2=A^2+B^2=(A+B)^2$.
Note: we only need $AB=0$ to obtain 1 and 2.
$BA = 0$ implies that the nullity of $B \geq$ the rank of $A$. $AB = 0$ implies that the nullity of $A \geq$ the rank of $B$.
$$ n(B) \geq r(A)$$ $$ n(A) \geq r(B)$$ $$ n(A) + r(A) + n(B) + r(B) = 2n$$
The final piece of the puzzle is that $A + B$ is invertible, this means that $r(A) + r(B) \geq n$ since we can't add two sets of vectors together and produce more linearly independent vectors than the sum of the rank of the two sets. The only conclusion is that $r(A) + r(B) = n$ and $n(A) + n(B) = n$.
To see that $A-B$ is invertible, $(A - B)^2 = A^2 + B^2 = (A + B)^2$
$\operatorname{rank}(AB) \geq \operatorname{rank} A+\operatorname{rank} B-n$ as $AB=0$ rank of $AB=0$ $$0 \geq \operatorname{rank} A+\operatorname{rank} B-n=0$$