A deal to safeguard four Harland and Wolff yards provides “tremendous security and opportunity” for both workers and communities, Scotland’s First Minister said.