"I had been working" is the past perfect continuous. It's used where you have two past events A and B, A happened before B, A lasted a significant amount of time, and A still had an effect at time B.
Cambridge says:
We use the past perfect continuous to talk about actions or events which started before a particular time in the past and were still in progress up to that time in the past:
It was so difficult to get up last Monday for school. I had been working on my essays the night before and I was very tired.
We can use the past perfect continuous to talk about events which started before a time in the past and which finished, but where the effects or results were still important at a point in the past:
It had been raining and the ground was still wet.
I think Cambridge's description is a bit confusing, because it's not as though the speaker was working until it was time to get up (although it can be used when B immediately follows A). What's important is that they had been working for a long time (earlier event A), and that had an effect at the time they were due to get up (later event B).
Regarding the difference between simple past perfect and past perfect continuous, Cambridge says:
We use the past perfect simple to refer to the completion of an activity and the past perfect continuous to focus on the activity and duration of the activity.
This is clearer: it's the fact that they spent a long time working and hence were tired, or that it had been raining for a long time and the ground was wet as a result.
Cambridge gives to explain the difference these sentences:
I'd waited an hour for the bus.
I'd been waiting an hour for the bus.
In the former, the wait is over and complete and that's the important thing; in the latter it's the amount of time that's important. You might say
I'd waited an hour for the bus, but when it came my journey was quick.
Here the wait wasn't too long.
But:
I'd been waiting an hour for the bus, and my feet were sore and I was soaked to the skin...
Ugh what a long wait!