Most of that code is also writing some bits in some registers directly and I have no idea what some of them do.
The datasheet will tell you.
I've seen quite a bit of code floating around that does either sleeping x amount of time or reading an external interrupt. But never both.
Both act on an interrupt. You just have to react in th ISR to do what you need to if that interrupt source woke the processor up.
Show us what code you already have and we try to add the necessary stuff that's missing. Implement one of the two cases (sleep with no button presses or sleep while waiting), so we have to help you adding just the other one.