Lua:
house:getItems()
player:getDepotChest(depotId[, autoCreate = false])
player:getInbox()
player:getItemCount(itemId[, subType = -1])
container:getItems([recursive = false])
Yep, should be possible.
Use the recursive nature of
container:getItems
to find all the items, then loop through them to find all items that match the item you are looking for.
House items obviously are a bit different, where you need to loop through them to find items matching, and also to find all containers, so you can search through their contents as well.
Lua:
container:getItemCountById(itemId[, subType = -1])
There is this function as well.. but I have a feeling that it only counts the top layer of a container.
Might be wrong, so worth a test.