Selling xbox but want to keep digitally downloaded games

Solution 1:

Your games are tied to your xbox live account. When you buy your new Xbox One, you just log in with your account and your games will be available to download again.
Before selling your Xbox though, you should reset it to factory defaults to remove any private information. You can do it by following these steps:

  1. Open the Settings application
  2. Scroll down to the System tab
  3. Select Console info & updates
  4. Navigate to the Reset console button.
  5. Select the Reset and remove everything option. This will entirely wipe your console to a factory-fresh state.

source