First order conditions in a Moral Hazard problem
Notice that MWG choose a wage function $w(\pi)$ to maximize profit, not a wage level $w$. As footnote 6 on p.481 of MWG says:


  The first-order condition for $w(\pi)$ is derived by taking the derivative with respect to the manager's wage at each level of $\pi$ separately.


In other words, you'd treat the wage function as a variable, e.g. $w(\pi)=z$, and solve 
\begin{equation}
\max_{z} \int [\pi-z]f(\pi|e)\mathrm d\pi +\gamma \left[\int v(z)f(\pi|e)\mathrm d\pi-g(e)-\overline u\right],
\end{equation}
which will yield the FOC 
\begin{equation}
-f(\pi|e)+\gamma v'(z)f(\pi|e)=0. 
\end{equation}
Substituting $z$ with $w(\pi)$, you'd have condition (14.B.3) in MWG.