Take one replica offline from an availability group
The database replica to be taken offline can be primary or secondary. 


The database taken offline should always be the secondary. 


  The database replica has to be take offline and online via transact SQL


That's possible.


  When the database replica is offline it should not be possible for it to execute requests. All existing connections must be moved to the other database replica or fail, so that the client can reconnect using the IP listener to the other replica.


Basically here's how it would go:


If the database replica that needs to be taken offline is a primary, check for the current secondary to be synchronized.
Set the database to be "taken down" as a non-readable secondary.
If the database replica was a primary, failover.
Do any other items you'd like here, such as removing it from the AG, etc.