How we retrieve the ‘tags’ and ‘attachment’ of the custom post which is created by wp_insert_post();

You can use:

$post_id = wp_insert_post($args);

to get the ID of the inserted post. You can try this:

   $terms = wp_get_object_terms($post_id, 'thread_tag');

to get the terms from your post with $post_id. You can check out the Codex:

http://codex.wordpress.org/Function_Reference/wp_get_object_terms

You can then use get_children()

$args = array(
'post_mime_type' => 'image',
'post_parent' => $post_id,
'post_type' => 'attachment'
);

$attachments = get_children( $args );

to fetch the attachments for this post. More on the Codex page:

http://codex.wordpress.org/Function_Reference/get_children

Edit:

To set the terms in the 'thread_tag' taxonomy for a given $post_id

wp_set_object_terms($post_id,array('term1','term2'),'thread_tag');

http://codex.wordpress.org/Function_Reference/wp_set_object_terms

error code: 523