I'm Portuguese and am going to Lima on AIR Canada. On my way back home I have a layover of 11 hours in Toronto. Can I leave the airport to visit the city? What happens to my luggage? Do I have to pass through immigration?
You will have to pass through customs and immigration. Your checked luggage should be checked through to Portugal. It appears you will have an eTA anyway, since you are transiting through Canada and not to the USA.
Assuming it's AC1947 arriving at 11:40am Toronto time, you can take the UP Express to connect to the subway system, and you should have a reasonable number of hours to poke around downtown.
You'll have to go through Canada Border Services Agency (CBSA) and security anyway, Canada has no real concept of international transfer. If it's all on Air Canada on a single ticket, your bags should be checked through. See https://www.torontopearson.com/Connecting.aspx# for details.
Since you need to go through immigration and security anyway, there is almost no time penalty in leaving the airport and 11 hours is plenty for a trip to town and back.
This assumes you are connecting at YYZ (Pearson airport) and not at YTZ (Billy Bishop airport). From YTZ, even an hour is enough to walk into town, have a beer (or two) and walk back to the airport :-)