I did this for 13 years. The basics are covered well in this thread already, so I'll just add a couple of points. The phrases we always used for contracts were "time and materials" versus "fixed price". We wanted time and materials, which means the client pays us a set rate for each unit of time we work (could be hours, days, sometimes months) plus the cost of any materials we need to do the job (software or SaaS lic…
Then you keep one of employees, later maybe more, on that SaaS and slowly change your revenue mix. Then you still might get some additional projects but you always have something to spend your FTE time on. In the end you change the company profile where you chase different things than just having butts in the seats.
But that might mean you are not getting any salary for months because you have to reinvest in your SaaS idea. Of course having a viable product idea is another very important point.
Upside on the other hand is that selling viable SaaS business will be easier than selling dev shop, because dev shop only has developers. When developers quit dev shop value goes immediately to 0, with SaaS you still might have IP and paying customers.