Gibbs free energy and maximum work I'm getting confused between two important results.
The Gibbs free energy is $G = H-TS$
where $H$ is the enthalpy and $S$ is the entropy.
When the temperature and pressure are constant the change in the Gibbs energy represents maximum net work available from the given change in system .
But $dG = VdP-SdT$, so at constant temperature and pressure i'm getting $dG=0$. This is the criteria for phase equilibria. 
I'm getting Gibbs free energy change at constant $T$ and $P$ as maximum work in one relation and zero in another. How are these compatible?
 A: There is no contradiction here. The change in Gibbs free energy tells you the maximum extractable work and at constant teperature and pressure $dG = 0$. The conclusion here is that you can extract no work while maintaining a fixed temperature and pressure. 
Why is this? Well you have 5 variables in your thermodynamic system $U, p, V, T$ and $S$. We can replace $U$ with $G$ in our list using $G = U +pV - TS$. Now we know from the fundamental relation that 
\begin{align}
G &= G(p,T)\\
V &= \left(\frac{\partial G}{\partial p}\right)_T\\
S &= \left(\frac{\partial G}{\partial T}\right)_p
\end{align}
So we have 5 variables and 3 constraint, leaving us with 2 degrees of freedom in our system. If we now impose another 2 constants, say by fixing $p$ and $T$, we have fully defined the state of our system. This means under these conditions we can extract no work because there is no other state we can move to in the transition.
If we do want to extract some useful work from our system there are 2 things we can do; either we can relax one of our constraints, say by allowing temperature to vary, or we can introduce additional physical degrees of freedom to the system, for example by allowing particle number to vary, and modify the expression for the change in $G$ accordingly, as @higgsss describes in they're answer. 
A: It means that there exists a third variable, say, $X$, describing the system. The corresponding thermodynamic relation should be
\begin{equation}
dG = VdP - SdT + \bigg(\frac{\partial G}{\partial X}\bigg)_{P,T} dX.
\end{equation}
If $X$ is not fixed, the system at constant $T$ and $P$ adjusts itself such that $G$ is minimized with respect to $X$. Then, $(\partial G/\partial X)_{P,T} = 0$, leading to $dG = 0$ even if $X$ changes by a small amount $dX$.
Now suppose that one controls the system to make it go through a thermodynamic process involving a change in $X$. During this process, the non-expansive work the system does on the outside is less than or equal to $-\Delta G$ (equal in a reversible process).
For example, consider a battery. The decrease in its Gibbs free energy from the fully charged state to the completely discharged state is equal to the maximum (ideal) electrical work the battery can do. In this case, the variable "$X$" is a measure of how far the chemical reaction inside the battery has proceeded.
A: More of a layman's answer because @higgss and @By_Symmetry answered with very good support.
I think a lot of the times that the 'work definition' of Gibbs Free Energy comes up during the discussion of hypothetical thermodynamic processes, "what if the volume decreased?", or "what if this chemical decomposed into these two chemicals?" so what happens to $G$?
Well, really what you're asking in those hypothetical scenarios is:
"What is $\Delta G$?" and yes, if $\Delta G < 0$ then the hypothetical process would happen. So the sign tells us whether it will happen, but the magnitude i.e. the actual value of $\Delta G$ is the maximum amount of work that can be extracted from the process if it is carried out reversibly.
Again, @higgss and @By_Symmetry gave pretty complementary and complete answers, but I thought that this might serve as a helpful, conceptual note in addition.
A: The math derivation can be made below
$$G=H-TS$$
$$dG = dH -d(TS)$$
$$dG = d(U+PV) -d(TS)$$
$$dG = dU + PdV +VdP -TdS - SdT$$
at constant pressure and temperature, $dP=0$, $dT=0$, 
$$dG = dU + PdV -TdS$$ 
From above, we know dG decreases when internal energy is transferred out, system does work and system entropy increases. 
