Consumer surplus is a measure of benefit to consumers resulting from paying less than the maximum price they are willing to pay.
Producer surplus is a measure of benefit to producers resulting from selling at a price higher than the minimum price at which they are willing to sell.
Referring to the supply-demand curve, these economic surpluses are represented by the area between either curve and the horizontal line fixed at the equilibrium price.
In this case, demand is zero when P = 40; this means there is a consumer surplus whenever P < 40. Similarly, supply is zero when P = 4; then there is a producer surplus whenever P > 4. In particular, any price below this point corresponds to a supply shortage. Realistically, producers would provide the good only if P > 4.
Set supply equal to demand and solve for P to find the equilibrium price:
40 - P = P - 4 ⇒ P = 22
At the minimum price P = 4, consumers demand 40 - 4 = 36 units and producers supply 4 - 4 = 0 units. At equilibrium price, consumers demand 40 - 22 = 18 units and producers supply 22 - 4 = 18 units. Then
CS = 1/2 (36 units - 18 units) ($22/unit - $4/unit) = $162
and
PS = 1/2 (18 units - 0 units) ($22/unit - $4/unit) = $162