Is it okay to take sleeping pills for extended periods?

Yes, at least some kinds.

So far, the only sleeping pill approved by the US Food and Drug Administration for long-term use is Lunesta, which has been shown to remain effective for at least six months, unlike some drugs that lose their effectiveness over time, prompting people to take more and more of them.