I would think that you take apart the door switch panel, and split the wire that connects to the fold-in side of the fold button. Then connect that wire to something that happens when you turn off the truck...
And then same for fold-out...just split its wire and connect it to something that runs when the truck is started, BUT something that doesn't constantly run or else the mirrors will be trying to fold out the whole time you drive.
That may not even be correct but it makes sense to me and it is what I would do if I were to try the project.
And for the fold in when you lock, there would be no way you could do that because one, you'd already have it set up to fold them in whenever the key hits the OFF position...and two, they would fold in whenever the truck auto-locks after you start driving. Very inconvenient.
Seems like I'm not the only one here with a vivid imagination.