Here is what I would do: override the canInteractWith() method in your custom container, and return false if the player is no longer holding your storage item.
You could perhaps store the buttons you want to change in an extra list, and then just iterate through that list and update the buttons when you want to perform the update.
You cannot have a global variable as a counter, since that will mess things up if several players use your item at the same time. I would recommend adding a capability, either to the player or to your custom item, which could hold your timer. You can read more about capabilities here.