Let $A^3=0$; check if $A^2-A+I$ is invertible and, if it is, find its inverse.
Is it possible to solve it this way?
$A^2-A+I=A(A-I)+I=B$
Multiply both sides by $A^2$:
$A^3(A-I)+ A^2= A^2B$
$A^2= A^2B$
$I=B$
$I$ is an invertible matrix!
Let $A^3=0$; check if $A^2-A+I$ is invertible and, if it is, find its inverse.
Is it possible to solve it this way?
$A^2-A+I=A(A-I)+I=B$
Multiply both sides by $A^2$:
$A^3(A-I)+ A^2= A^2B$
$A^2= A^2B$
$I=B$
$I$ is an invertible matrix!
$$(A+I)(A^2-A+I)=A^3+I$$
Hence,
$$(A+I)(A^2-A+I)=I$$
No, you can't remove $A^2$ in the last step, because $A$ is not invertible.
For instance, $A=\begin{pmatrix}0 & 1 \\ 0 & 0\end{pmatrix}$ satisfies $A^3=0$, but $$ A^2-A+I=\begin{pmatrix}1 & -1 \\ 0 & 1\end{pmatrix}\ne I $$ contradicting your conclusion.
The problem with your proof is that you consider by saying $A^2 = A^2 B \implies I = B$ that $\mathcal{M}_n(\mathbb{K})$ is an integral domain. An integral domain is a ring $R$ such as : $$\forall a, b \in R, \ ab = 0 \implies a = 0 \lor b = 0$$ In such a ring, if $c \in R\setminus\{0\}$, we have : $$\forall a, b \in R, \ ac = bc \implies (a-b)c = 0 \implies a-b = 0 \lor c = 0 \implies a = b$$ ...which is the property you've used.
However, $\mathcal{M}_n(\mathbb{K})$ isn't an integral domain, for exemple : $$\begin{bmatrix} 1 & 0 \\ 0 & 0 \end{bmatrix} \times \begin{bmatrix} 0 & 0 \\ 0 & 1 \end{bmatrix} = \begin{bmatrix} 0 & 0 \\ 0 & 0 \end{bmatrix}$$
Ahmed S. Attaalla's answer is a correct proof that $B$ is an invertible matrix.
You can go further with your approach to make it work. One route through is to try to express the left-hand side as multiples of $B$ plus the original $I$ (you can do that with $A^2=A^2B$ so need to attack the $A$) $$A^2-A+I=B$$Multiply by $A^2$ as you did $$A^2=A^2B$$ Now also multiply by $A$ $$-A^2+A=AB$$Substitute the result for $A^2$ in this latest result $$-A^2B+A=AB; A=A^2B+AB$$ Now sub back into the original equation $$A^2B-A^2B-AB+I=B$$ or $$I=B+AB=IB+AB=(I+A)B$$