If the size of the inventory is of a reasonable size, I would probably use a brute force guess and check method. Each item of any size should have a "base" tile, for example the top left corner. Then when placing the item in in inventory array, check each additional spot that item requires to fit, and only proceed if all required spots are valid.
For auto fitting on pickup, you would loop each available slot in the inventory starting with the base tile and checking for validity until it fits or fails.
Each item should have instance variables to describe it's size either in terms of array positions, or width and height of all items are rectangular.