This question builds on a series of questions looking for elementary proofs that $AB=\mathrm{Id}$ implies $BA=\mathrm{Id}$, for $A$ and $B$ both $n \times n$ matrices over a commutative ring. First the question, then motivation, then a small bit of progress.
Let $R$ be a commutative ring. Let $A$ and $B$ be $n \times n$ matrices with entries in $R$ satisfying $AB=z \mathrm{Id}_n$ for some $z \in R$. We cannot conclude that $BA = z \mathrm{Id}_n$: Take $R=\mathbb{Z}$, $z=0$, $A = \left( \begin{smallmatrix} 0 & 1 \\ 0 & 0 \end{smallmatrix} \right)$ and $B = \left( \begin{smallmatrix} 1 & 0 \\ 0 & 0 \end{smallmatrix} \right)$. However, we can conclude $z^n BA = z^{n+1} \mathrm{Id}$ (proof below).
What is the smallest $m$ (as a function of $n$) for which we can conclude $z^m BA = z^{m+1} \mathrm{Id}$?
Motivation Suppose that we can do this for some particular $m$ and $n$. Let $k[a,b,z]$ be the polynomial ring in $2n^2+1$ variables, $a_{ij}$, $b_{ij}$ and $z$ (over some field $k$). Let $S$ be the quotient of $k[a,b,z]$ by the $n^2$ relations gotten by expanding the matrix product $AB=z \mathrm{Id}_n$.
Since this question is framed for an arbitrary commutative ring, it applies in particular to $S$. So, if the answer is "yes" for some $(m,n)$, then the entries of $z^m BA - z^{m+1} \mathrm{Id}_n$ are zero in $S$. In other words, they lie in the ideal of $k[a,b,z]$ generated by the entries of $AB-z \mathrm{Id}_n$. I.e. we must have polynomial relations $$z^m \left( \sum_r B_{ir} A_{rj} - z \delta_{ij} \right) = \sum_{k, \ell} P_{ij}^{k \ell}(a, b, z) \left( \sum_s A_{ks} A_{s\ell} - z \delta_{k \ell} \right) \quad (\ast)$$ for some polynomials $P_{ij}^{k \ell}(a, b, z)$.
Put a grading on $k[a,b,z]$, where $\deg a_{ij} = \deg b_{ij}=1$ and $\deg z=2$. Then we may assume that the $P_{ij}^{k \ell}$ have degree $m$. Plugging in $z=1$ to $(\ast)$, we get a high school algebra proof that $AB=\mathrm{Id}_n$ implies $BA = \mathrm{Id}_n$ involving polynomials of degree $\leq m$.
Conversely, if we have a proof that $AB=\mathrm{Id}_n$ implies $BA = \mathrm{Id}_n$ by pure high school algebra (adding, multiplying and dividing polynomials and substituting in the equations $AB = \mathrm{Id}_n$) then we can take every formula in that proof in replace each $1$ by an appropriate power of $z$ to make the equations homogenous. The result will be a proof of $(\ast)$ for some $m$ and, again, the size of $m$ is a measure of the complexity of the proof.
Minor progress It is good enough to take $m=n$. Proof: simplify $(\det B) \mathrm{Ad}(A) A B A$ in two ways. One way gives $$(\det B) {\Big (} \mathrm{Ad}(A) A {\Big )} B A = (\det B) (\det A) BA = (\det A) ( \det B) BA = \det(AB) BA = z^n BA$$ the other gives $$(\det B) \mathrm{Ad}(A) {\Big (} A B {\Big )} A =(\det B) \mathrm{Ad}(A) z A = z (\det B) (\det A) = z \det(AB) = z^{n+1}.$$
When $n=1$, we can take $m=0$, as $R$ is commutative. For $n=2$, the above example of $z=0$, $A = \left( \begin{smallmatrix} 0 & 1 \\ 0 & 0 \end{smallmatrix} \right)$ and $B = \left( \begin{smallmatrix} 1 & 0 \\ 0 & 0 \end{smallmatrix} \right)$ shows we need $m \geq 1$ and it is easy to adapt this to show that we need $m \geq 1$ for any $n \geq 1$.
This is all I know! I don't even have an example to show that $m \geq 2$ is necessary for any $n$, although my gut says $m$ should grow linearly with $n$.
Just some considerations:
Suppose $AB=zI_n$. If $z=0$, then $zBA=0=z^2I_n$, so $m=1$ is ok.
If $z\neq 0$ is not a zero divisor, consider the multiplicatively closed set $S_z:=\{z^n, n\in\mathbb{N}\}$. Since $z$ is not a zero divisor, we have an injection of $R$ in $S_z^{-1}R$, and then we can see the relation $AB=zI_n$ in this bigger ring. We have then $$\left(\frac{1}{z}A\right)B=I$$ hence $$B\left(\frac{1}{z}A\right)=I_n,$$and finally $$BA=zI_n,$$ that means $m=0$ is ok. If $z$ is nilpotent, we have $z^m=0$ for some $m\geq 2$. Then, $$0=z^mBA=z^{m+1}I$$ The argument above fail if $R$ is not commutative, cause in general $AB=I$ doesn't imply $BA=I$ (ring that satisfies this condition are called stable finite, it would be interesting to understand if the localization of a stable finite ring si still stable finite).