Ok, if you cycle at legal speed (15mph), on throttle only you would use 15wh/miles.
So for 40miles you would need 15wh*40miles = 600wh battery.
Considering you would need about 20% additional power to preserve battery, a 720Wh battery would fit you.
So for your case, a 36V20AH battery would...