Theorem. Let $X$ and $Y$ be no empty sets. Then $$\big(|X|\le |Y|\big)\quad\text{if and only if}\quad\big(\exists\;f\colon Y\to X\;\text{onto}\big).$$
Proof.$(\Rightarrow)$ Let $|X|\le|Y|$, then by definition exists $g\colon X\to Y$ injective, if $g$ is onto we finished. If $g$ is not onto, we consider $g\colon X\to g(X)\subset Y$ which is invertible, therefore we can consider $g^{-1}\colon g(X)\to X$. We can extend $g^{-1}$ to an onto function $f$ on all Y in a following way: let $x_0\in X$, $$ f(y):= \begin{cases} g^{-1}(y) & \text{if $y\in g(X)$} \\ x_0 & \text{if $y\in Y\setminus g(X)$}. \end{cases} $$ The application $f\colon Y\to X$ is onto.
Question 1. Is it correct?
$(\Leftarrow)$ Let $f\colon Y\to X$ onto and we define $g\colon X\to Y$ in the follow way: for all $x\in X$, $g(x)=y$, where $y\in Y$ is such that $x=f(y)$ (we remember that $f$ is onto). We observe that for all $x\in X$ we have $$f\circ g(x)=f(g(x))=f(y)=x.$$ Therefore, $f\circ g=\text{id}_X$.
Question 2. If $f$ is onto and $f\circ g$ invertible, can we conclude that $g$ is injective? If the answer is yes, How can I show it?
Thanks!
Q1 is correct, though you don't need to separately handle the case when $g$ is onto.
Q2 Yes, moreover if $f\circ g$ is injective with arbitrary $f$, it follows that $g$ must be injective.
Note that the axiom of choice is used in order to simultaneously pick a preimage $y$ for all elements $x$.