There's nothing wrong with getting back in touch because you're looking for work. In fact, I'd recommend against random "hey how are you it's been a while" contact that slowly morphs to "oh yeah btw I'm looking for a job." It's dishonest and it doesn't fool anyone.
However, straight up "can I come work for you?" is very direct and may leave the old manager feeling pressured or unable to decline, resulting in potential embarrassments to you both like an interview you could never succeed in. Instead, be clear that you are looking for work and asking for help, but don't ask your manager to hire you. If the manager happens to be hiring, or to be in a position to open up a space for you, you don't need to suggest such a thing - a good manager can think of that themselves.
I would probably email something like this:
Hi [name], hope this finds you well. A lot has been going on for me these past few years, and I'm looking for a job change, so I'm reaching out to people I've enjoyed working with in the past. If you know of something available that would suit me, I'd really appreciate any introductions or information you can provide. Since we last worked together I've [learned C++, shipped 3 commercial products, been promoted to senior DBA, taken on more project management, whatever] and I'm looking for a role where I can [continue to learn and grown, lead a team, get into Internet of Things work, speak at conferences several times a year] and [some other thing you want.] Are you aware of anything?
Key points about this email are that it lets your manager know how you've grown since your last communication, and describes the position you want. Don't make your manager do all the work of figuring out what would be good for you. In addition to avoiding the pressure of directly asking for a role with the manager, this approach also means that the manager can tell you about "a great opportunity with a friend of mine" without it being some sort of consolation prize to make up for not having a job to offer you.
Depending on the response you get you could elaborate that "I really enjoyed working for you and it would be really cool if there was an opening at your firm" but I wouldn't include that in the first email.