There are other factors that you’ll discover along the way, but basically it boils down to: move all that’s CPT related from your theme’s functions.php
to a plugin file.
Create a PHP file, put the plugin’s header information, add to the plugins folder, activate.
Now, you separated appearance (theme) from functionality (plugin). Here are two fundamental Q&A’s here in WPSE:
And here a related blog post.
You’ll find many examples of plugin-development in the site archives.