What I've done in the past in this scenario is use a combination of SlowCheetah and ReplaceTokens.
With SlowCheetah, you can create different app.config files for the different environments. It might not necessary to create different app.config files for the different environments, but I mostly do it because it makes it easier to separate executing the application locally and in production.
With the ReplaceTokens task in an Azure Release pipeline, you can replace certain tokens in an app.config (or other configuration files) with variables that are defined in the Release pipeline itself.
I understand your concern about protecting sensitive data like usernames and passwords; the Azure Release pipelines support 'hidden variables', so you can hide your sensitive data; just mark these variables as 'hidden' by clicking on the picture of the key lock at the right of the value box.
For a really secure application you might use the Azure KeyVault, but that might be a too complex solution for this.