Hi,
The line 487 means that the variable "$product" is not an object, so that the variable contains a "null" or a "false".
$product->categories = $db->loadObjectList('category_id');
Which means that the template_id configured target a product which does not exists anymore.
Same thing for the second error, the "foreach" is made on the return for the template loading.
If the template_id does not exist anymore, the load can't work and you got the error.
I can add "security" code in order to check the content ; but the current problem is in your configuration.
Regards,