Method:1
When $f:A\to B$ is not one-one,
$$
f(x_1)=f(x_2)=y' \text{ for } x_1\neq x_2\in A,y'\in B\\
\implies f^{-1}(y')=f^{-1}(f(x_1))=x_1 {\quad\&\quad} f^{-1}(y')=f^{-1}(f(x_2))=x_2
$$
For the inverse function $f:B\to A$, we have $f^{-1}(y')=x_1$ and $f^{-1}(y')=x_2$. Hence, $f^{-1}$ is not defined as we have two images for $x_1$ and $x_2$ for one preimage $y'$.
$\implies$ for $f$ to be invertible it must be one-one.
When $f:A\to B$ is not onto,
there exists atleast one $y'\in B$ which does not have a preimage in set $A$. When we define $f^{-1}:B\to A$, $y'$ becomes preimage which will not have any image in set $A$, thus $f^{-1}$ is not defined.
$\implies$ for $f$ to be invertible it must be onto.
Therefore,
$f$ is invertible iff $f$ is both one-one and onto.
Method:2
If $f:A\to B$ is invertible, then $f^{-1}\circ f=I_A$ and $f\circ f^{-1}=I_B$.
$$
f^{-1}\circ f(x_1)=f^{-1}\circ f(x_2)\implies f^{-1}(f(x_1))=f^{-1}(f(x_2))\\\implies x_1=x_2\text{ $\bigg($since $f^{-1}\circ f(x)=x, \forall x\in A\bigg)$}
$$
Thus, $f^{-1}\circ f$ is one-one $\implies$ $f$ is one-one.
$f\circ f^{-1}:B\to B$ defined as $f\circ f^{-1}(y)=y,\forall y\in B$. For all $y$ in the codomain $B$ have one preimage $y$ in the domain $B$.ie, Codomain of $f\circ f^{-1}$=Range of $f\circ f^{-1}=B$
Thus, $f\circ f^{-1}$ is onto $\implies$ $f$ is onto.
$\implies$ $f$ is bijective