issue with saving custom metaboxes fields

You have to register the taxonomy before you can add terms to a post type. Register the taxonomy after you register the custom post type. If you are not the one that is registering the post type, you will need to find where it is being registered and make sure you register the taxonomy afterwards. After both those are registered you can add terms to posts using wp_set_object_terms.