There are two methods and the second one is comfortable in this case.
The methods are (in terms of conditions)
(1) If there exists a positive number r such that for every independent variable x in (a − r, a) we have f′(x) ≥ 0, and for every x in (a, a + r) we have f′(x) ≤ 0, then f has a local maximum at a.
(2) If f"<0, then f has a local fmaximum at x (independent variable value)
Hence find second derivative of both TP1 and TP2 in terms of the four independent variables T,E,W,p separately and if all of them are negative, then you have an optimum f value. Else only those variable that give f"<0 behave such as to give you an optimum f.
Hope I have not confused your already somewhat clear mind!