Everyt capital letter here is written in a per mole basis, so I stick with your nomenclature. E.g., $G$ has units of $\pu{J mol ^{-1}}$, etc.
Where does this expression comes from? Why does it exists in the first place? What does it mean?
Lets put the function $G/RT$ as an exact differential. I see two variables, $G$ and $T$, so we have to differentiate with respect to $G$ and $T$
$$ \mathrm{d}\left(\frac{G}{RT}\right) =
\frac{1}{RT} \mathrm{d}G -\frac{G}{RT^2}\mathrm{d}T \tag{1} $$
In the first term $T$ was constant when we differentiated with respect to $G$, and in the second term $G$ was constant when we differentiated with respect to $T$. That's all.
Not every expression is thermodynamics is useful. However, this expression exists because we can eliminate the entropy in favor of enthalpy, and that's the reason. Remember that in its fundamental expression $\mathrm{d}G = V\mathrm{d}p - S\mathrm{d}T$, we have $S$ there.
We do this. We combine Eqn. (1) with $G = H-TS$ and also the fundamental equation $\mathrm{d}G = V\mathrm{d}p - S\mathrm{d}T$
\begin{align}
\require{cancel}
\mathrm{d}\left(\frac{G}{RT}\right) &=
\frac{1}{RT} (V\mathrm{d}p - S\mathrm{d}T) -\frac{H - TS}{RT^2}\mathrm{d}T \\
\mathrm{d}\left(\frac{G}{RT}\right) &=
\frac{V}{RT}\mathrm{d}p - \cancel{\frac{S}{RT}\mathrm{d}T} -
\frac{H}{RT^2}\mathrm{d}T + \cancel{\frac{S}{RT}\mathrm{d}T} \\
\mathrm{d}\left(\frac{G}{RT}\right) &=
\frac{V}{RT}\mathrm{d}p - \frac{H}{RT^2}\mathrm{d}T \tag{2}
\end{align}
and there you go. Eqn. (2) now is a function of enthalpy rather than entropy.
Is it related to Ideal gases? By this I mean, is it somehow derived from the ideal gases framework?
Eqn. (1) doesn't depend on the model, it is very general. It is valid as long as you are talking about a fluid of only one component.
Then my book makes use of this expression
$$ d(\frac {G^R}{RT})_{P=0} \equiv J$$
I will skip this question and come back after we derived the next one.
I'm trying to understand these details to get a sense of how to obtain this final expression
$$\frac {G^R}{RT}= \int_{0}^{P} (Z-1)\frac{dP}{P}$$
We are going to do this: we restrict Eqn. (2) for a constant temperature process, so the guys with $\mathrm{d}T$ go away. Then, we write what is left for an ideal gas and also for a real gas
\begin{align}
\mathrm{d}\left(\frac{G^\mathrm{ig}}{RT}\right) &=
\frac{V^\mathrm{ig}}{RT}\mathrm{d}p \tag{3} \\
\mathrm{d}\left(\frac{G}{RT}\right) &=
\frac{V}{RT}\mathrm{d}p \tag{4}
\end{align}
and subtract Eqn. (4) from (3), where we will define the residual property for a general property $X$ as $X^\mathrm{R} = X - X^\mathrm{ig}$
\begin{align}
\mathrm{d}\left(\frac{G}{RT}\right) -
\mathrm{d}\left(\frac{G^\mathrm{ig}}{RT}\right) &=
\frac{V}{RT}\mathrm{d}p - \frac{V^\mathrm{ig}}{RT}\mathrm{d}p \\
\mathrm{d}\left(\frac{G - G^\mathrm{ig}}{RT}\right) &=
\frac{V - V^\mathrm{ig}}{RT}\mathrm{d}p \\
\mathrm{d}\left(\frac{G^\mathrm{R}}{RT}\right) &=
\frac{V^\mathrm{R}}{RT}\mathrm{d}p \tag{5}
\end{align}
Now we would like the compressibility factor to pop up. For an ideal gas the molar volume is $V = RT/p$, and for a real gas $V=ZRT/p$, so that
$$ V^\mathrm{R} = V - V^\mathrm{ig} = \frac{ZRT}{p} - \frac{RT}{p} =
(Z-1)\frac{RT}{p} \tag{6} $$
Combining Eqns. (5) with (6) and integrating
\begin{align}
\require{cancel}
\mathrm{d}\left(\frac{G^\mathrm{R}}{RT}\right) &=
\dfrac{(Z-1)\dfrac{\cancel{RT}}{p}}{\cancel{RT}}\mathrm{d}p \\
\mathrm{d}\left(\frac{G^\mathrm{R}}{RT}\right) &=
\dfrac{Z-1}{p}\mathrm{d}p \rightarrow \boxed{
\frac{G^\mathrm{R}}{RT}(p) = \frac{G^\mathrm{R}}{RT}(p \to 0) +
\int_0^p \dfrac{Z-1}{p}\mathrm{d}p} \tag{7}
\end{align}
There we have derived the expression. I will make the following points to your other questions:
- In chemical engineering we sometimes face real gases, so the approach to obtain more accurate values is the followinge. First we calculate all thermodynamic properties as gases behaved ideally, and then we correct them. This makes some derivations easier, hence why residual properties exist. For example, you know that for a constant temperature process, the change in Gibbs free energy when pressure changes is
\begin{equation}
\Delta G^\mathrm{ig} = RT\ln\frac{p_2}{p_1}
\end{equation}
How can we correct this value for real gases? We write Eqn. (7) two times, one for $p_1$ and the other for $p_2$, and subtract them
\begin{align}
\frac{G^\mathrm{R}}{RT}(p_1) = \frac{G^\mathrm{R}}{RT}(p \to 0) &+
\int_0^{p_1} \dfrac{Z-1}{p}\mathrm{d}p \qquad
\frac{G^\mathrm{R}}{RT}(p_2) = \frac{G^\mathrm{R}}{RT}(p \to 0) +
\int_0^{p_2} \dfrac{Z-1}{p}\mathrm{d}p \\
\frac{G^\mathrm{R}}{RT}(p_2) - \frac{G^\mathrm{R}}{RT}(p_1) &=
\int_0^{p_2} \dfrac{Z-1}{p}\mathrm{d}p - \int_0^{p_1} \dfrac{Z-1}{p}\mathrm{d}p \\
\frac{\Delta G^{R}}{RT} &=
\int_{p_1}^{p_2} \dfrac{Z-1}{p}\mathrm{d}p \tag{9}
\end{align}
- That $J$ that appears in book has to do with what happens with the quantity $G^\mathrm{R}/RT$ as the pressure goes to zero. Sometimes, we can state how a thermodynamic property will behave in some extreme limits. In this case, we don't know what happens to this quantity in general. It is said to be indertermined However, don't go so deep, because you will always be interested in changes of $G$. As you see in Eqn. (9), the constant is blown off, so we are happy. We could have chosen other lower limit of integration and things would have worked fine.
- If you want to have higher precision in your calculations, you need to integrate Eqn. (9). You can do this with measurements of $pVT$ data in the laboratory, or use an equation of state where $Z$ may be function of two variables.