Well, the maximum or minimum of a function occurs when the first differential of the function is 0, as this implies that the function is not changing at that point.

Now, setting dP/dR equal to 0 gives: (can't be bothered to do it fancy, sorry)

0 = (E^2)(r-R) / (R+r)^3 = [(E^2) / (R+r)^3](r-R)

If we divide both sides by (E^2) / (R+r)^3 then we get:

0 = r - R

(as 0 / a = 0, where a is any number)

Adding R to both sides gives R = r, which is saying that at the maximum power, the internal resistance is equal to the total resistance in the resistor. This means that we can now write the maximum power of the function by substituting this fact in to give P not in terms of R. (and thus no unknowns for P)