The definition of a derivative: let $y=y(x)$. Then, $\dfrac{dy}{dx}= \dfrac{y(x+dx)-y(x)}{dx}$ . Now consider : $$ cos(x)=\frac{sin(x+dx)-sin(x)}{dx}$$ $$cos(x)dx=sin(x)cos(dx) + cos(x)sin(dx)-sin(x)$$ $$cos(x)[(dx-sin(dx))]=sin(x)[(cos(dx)-1)]\tag{E01}$$
And: $$-sin(x)=\dfrac{cos(x+dx)-cos(x)}{dx}$$ $$-sin(x)dx=cos(x)cos(dx) - sin(x)sin(dx)-cos(x)$$ $$cos(x)[(cos(dx)-1)]=sin(x)[(sin(dx)-(dx))] \tag{E02}$$ E01 and E02 together imply $cos(dx)=1$ and $sin(dx)=dx$. Both of which give the same result if we use the Maclaurin series for $cos$ and $sin$: that $(dx)^2$ and higher powers are exactly zero.
We can take up an easier example : consider $y(x)=\pi x^2$. By the formula, $$\dfrac{dy}{dx}=2\pi x=\dfrac{\pi(x+dx)^2-\pi(x)^2}{dx}$$ $$2\pi xdx=\pi[(x+dx)^2-(x)^2]=\pi[2xdx + (dx)^2]$$
Which implies $(dx)^2$=0.
Is there a formal definition of "differentials" that allows us to prove that $(dx)^2=0$? Or do we accept it as an "axiom"?
You are omitting that you must take the limit for $dx\to0$.
It is true that
$$\lim_{dx\to0}\frac{dx}{dx}=1$$
and
$$\lim_{dx\to0}\frac{dx^2}{dx}=0$$ by the theory of limits.
Then
$$\lim_{dx\to 0}\pi\frac{(x+dx)^2-x^2}{dx}=\pi\lim_{dx\to 0}\frac{2x\,dx}{dx}+\pi\lim_{dx\to 0}\frac{dx^2}{dx}=2x$$ is rigorous.