Yes, we need energy when we sleep because even when we sleep, most of our organs have to keep working. For example, heart needs to pump blood, we keep breathing, filtration is kidneys, etc. keeps happening. Energy is needed for those activities. So we need energy even when we sleep.