How to stay motivated and optimistic about an academic or industrial career with an extended PhD? I am pursuing my PhD in Canada in Mechanical engineering and will graduate this November. This brings my PhD time to a total of 5 years 3 months. I already had a master's degree. I have not yet started looking for postdoc positions but I have heard from one of my lab's alumni that they were asked about their extended PhD duration during postdoc and industry position interviews.

I had coursework in first semester, but after that, all my time was invested in my research. So, I don't have the reasoning that my US counterparts have for their PhD extending over 5 years. I was unfocused for a better part of a semester during my 3rd year, so that might have caused this delay.
On top of that, I am submitting my research to journals now, so I don't have any proof of productivity for the past 4 years.

I have two questions:
1) does an extended PhD duration really frowned upon in academia and industry (for a research scientist position), if so, any suggestions to counteract a question on that? 
2) A vague question: How can I stay motivated and optimistic about completing my thesis and working towards an academic or a research scientist career in the future?
I'll say something only about your first concern. 

You can't change the past. You are where you are. However, I wouldn't be overly concerned with anecdotal remarks about what is expected or not. You have a history and if asked about it, just recount it honestly. Don't apologize for taking a few extra months or even years. 

The funny thing about (real) research is that you can't do it on a schedule. The insights and the background work take time to mature. It isn't like manufacturing a complex artifact like an automobile that can be optimized to the second. Research problems worth the effort are hard and the solutions come when they come. Sometimes spending more hours on them helps. Sometimes taking a break, especially a mental break, helps. 

But anyone who says "I will do this significant piece of work and be done in three years" is deluding themselves. I expect other people with research experience to recognize and respect that. If they don't, I expect that they haven't really worked on anything difficult lately and carried it to completion. 

You do what you can do with the constraints that you have. Hopefully you learn something valuable and are able to write it up and get your degree. But the path is both winding and difficult. 

When I went to grad school it was still possible to get a math PhD in four years out of undergraduate. I took seven. My career wasn't what I expected, due to economic factors beyond my control, but I had a rewarding career in academia. Nowadays seven is closer to the norm, unfortunately.