Get list of roles with 0 Identities in them and list of all access profiles that are not tied up to any of the roles

Is there a way to export roles that has 0 identities in them?
Also is there a way to get list of access profiles that are not tied to any of the roles?

Using the APIs you can get all Roles and Access Profiles (50 at a time).

There is also an API once you have the Role id to get the users assigned to that role.

To get the Access Profiles not attached to Roles, you would need to save the list of all Access Profiles, then iterate through all of the Roles and track which Access Profiles are attached. Using this you can find the diff (not attached).