Firstly, I assume you mean a smart contract you will deploy, as you can't change the functionality of one already deployed.
With ERC20, there is no function triggered on your contract when it receives tokens, the token contract itself is all that gets called. To detect the change you would need some external program to monitor the blockchain for relevant transactions and fire some method on your contract when it finds one, but this solution isn't ideal.
Alternatively if you have full control over the software that might be sending tokens to your contract, you can have this 'approve' your contract address on the token contract, and then call a function on your smart contract which will perform the 'transferFrom' function, so you are in control of the transfer and can handle it as desired.
In either case you will need to feed your smart contract the token address in order to check balances or perform the 'transferFrom'
If you opt only for compatibility with ERC223 tokens instead, the situation is much simpler - any ERC223 token transfer to your smart contract will call the 'tokenFallback' method on your contract, so you can simply add your desired functionality there.