You can show one of the inequalities using your approach, by adding and subtracting $XY$ and $I$ in your expression. For the other inequality to achieve equality is trickier. So I will approach it in a different manner. We will show instead the direct sum decomposition of their images:
$$Im(X-Y) = Im(X+I)(Y-I) \oplus Im(X-I)(Y+I),$$
which implies $rank(X-Y) = rank(X+I)(Y-I) + rank(X-I)(Y+I)$.
To show this direct sum decomposition, we show the sum spaces are equal with trivial intersection.
Part 1: $Im(X-Y) \subset Im(X+I)(Y-I) + Im(X-I)(Y+I).$
Indeed, any vector in $Im(X-Y)$ is of the form $(X-Y)v$ for some $v\in \bf C^n$. Note
$$ (X-Y)v = (XY + Y - X -I)(v/2) + (XY-Y+X-I)(-v/2)\\
=(X+I)(Y-I)(v/2) + (X-I)(Y+I)(-v/2)\\
\in Im(X+I)(Y-I) + Im(X-I)(Y+I).$$
Part 2: $Im(X-Y) \supset Im(X+I)(Y-I) + Im(X-I)(Y+I).$
Indeed, an element in $Im(X+I)(Y-I) + Im(X-I)(Y+I)$ is of the form $(X+I)(Y-I)v + (X-I)(Y+I)w$ for some $v,w\in \bf C^n$. Next, we use the fact that $Y^2 = I$, so
$$(X+I)(Y-I)v + (X-I)(Y+I)w \\
=(XY-X+Y-{\color{blue} I})v +(XY +X -Y -{\color{blue} I})w\\
= (XY-{\color{blue} Y^2} -(X-Y))v + (XY - {\color{blue} Y^2} +(X-Y))w\\
= (X-Y)(Y-I)v + (X-Y)(Y+I)w\\
= (X-Y)[(Y-I)v+(Y+I)w]\\
\in Im(X-Y).$$
Part 3: $Im(X+I)(Y-I) \cap Im(X-I)(Y+I) =(0)$.
Suppose $z$ is in the intersection, so we have $z=(X+I)(Y-I)v = (X-I)(Y+I)w$ for some $v,w$. Then multiply $(X-I)$ from the left to both sides, giving
$$(X-I)(X+I)(Y-I)v = (X-I)(X-I)(Y+I)w \\
\implies (X^2 -I)(Y-I)v = (X-I)^2(Y+I)w\\
\implies 0 = (X-I)^2(Y+I)w
$$ since $X^2 = I$. But
$$(X-I)^2(Y+I)w = (X^2 -2X+I)(Y+I)w \\
=(2I-2X)(Y+I)w = -2(X-I)(Y+I)w = 0 $$
so $(X-I)(Y+I)w= z=0$. Hence the intersection is trivial.