How can I create a custom module that can be reinstalled without throwing an error?
You can make your config dependent on the module by adding this to the relevant config file(s):

dependencies: 
  enforced: 
    module: 
      - module_name


When your module is uninstalled, the config will go with it. You probably want to delete any content and field instances in hook_uninstall as well.