The maximum area is obtained when half the fence (18 m) is used parallel to the wall. Then the remaining half of the fence forms the other two (equal, 9 m) sides.
The dimensions of the pen will be 9 m by 18 m.
_____
If x represents the width of the pen (two sides out from the wall), then the area is
... area = x·(36 -2x) = 2x(18 -x)
This expression describes a parabola that opens downward and has zeros at x=0 and x=18. The line of symmetry (and vertex) is halfway between these zeros, at x=9. Hence the width of the pen is 9 m and its length is 36-2·9 = 18 m.