At one time there was a verb for working late by candlelight - elucubrate. Henry Cockeram defined that in his The English dictionarie, or an interpreter of hard English words, 1623:
"Elucubrate, to doe a thing by candlelight."
In 1635 English author Francis Quarles wrote in Emblemes,
"Wee spend our mid-day sweat, or mid-night oyle;
Wee tyre the night in thought; the day in toyle."
Candles, or midnight oil, was needed when there was no electricity. So now that we have electricity the phrase isn't necessary but is still used to figuratively mean that someone is working long and late hours.