you can use pre_get_posts
filter hook and set the post__not_in
parameter of the query ex:
function exclude_from_search_filter($query) {
if ( !$query->is_admin && $query->is_search) {
$query->set('post__not_in', array(40, 9) ); // id of page or post
}
return $query;
}
add_filter( 'pre_get_posts', 'exclude_from_search_filter' );