How can I save a setting field with multiple checkbox options generated by a foreach loop on a custom wordpress admin page?

You can use the function xprofile_get_field_data( $field, $user_id, $multi_format)

 * @param mixed  $field        The ID of the field, or the $name of the field.
 * @param int    $user_id      The ID of the user.
 * @param string $multi_format How should array data be returned? 'comma' if you want a
 *                             comma-separated string; 'array' if you want an array.