Sometimes people are referring to mechanical objects as "she":
I love my car. She always gets the best service.
Are there any rules when it is appropriate to use "she" instead of it, and is "he" ever used in such context?
The pronoun "she" is sometimes used to refer to things which can contain people such as countries, ships, or vehicles, or when referring to certain other machines. This, however, is considered a stylistically marked, optional figure of speech. This usage is furthermore in decline and advised against by most journalistic style guides such as the Chicago Manual of Style. If used, the terms she, her, and hers are always used, regardless of the entity's name - for example, "The U.S.S. John F. Kennedy (CVA-67) was laid down October 22, 1964. She was launched on April 1, 1967..."
"He" in reference to an inanimate object has not, as far as I'm aware, ever been common usage in English.
First off, you're trying to find a "rule" that predicts what human brains will do. Humans tend to do what they like and they don't like rules. "As many exceptions as rules", etc.
That said, the English practice of referring to inanimate objects as "she" appears to concentrate in areas historically dominated by males (navies, military, locker-rooms, car-repair shops, etc.)
Objects referred to as "she" by those groups tend to have the following characteristics:
As the objects are seen as both required for survival and likely to kill them, males tend to supersticiously think of the object as feminine. This allows them the hope that the object might be subject to cajoling and/or flattery as a means of increasing their odds of survival.
Note: This turned into more of an opinion piece than I originally intended. Your mileage may vary and I have nothing to help back any of this up.
Regarding the usage of "he" in place of "she", this is possible as a backlash against the typical "she" usage:
(by a woman) I love my car. He always gets the best service.
This isn't really "common", per se, and really only serves as a Take That against men's use of an inanimate she.
Another borderline exception is the Judeo-Christian God:
God is great. He loves us very much.
The non-gender aspect of God is a much heated topic and the non-existence of a gender neutral pronoun forces people to choose male or female. Another backlash occurs when authors purposefully swap it:
God is great. She loves us very much.
This also serves as a Take That but more directly targets the male dominated leadership of the modern church. That being said, this doesn't quite satisfy your query since God is typically seen as animate and personal. "It" wouldn't really feel right.
The only place you will traditionally invoke an inanimate he is when you are referring to a specific entity and wish to anthropomorphize it with typical male emotions and traits. Note the difference in style:
A tornado is coming! It will destroy us all!
A tornado is coming! She will destroy us all!
A tornado is coming! He will destroy us all!
Tornado may not be the best example, but each of these will bring slightly different connotations to mind. "It" is an abstracted, non-personal usage that attaches no emotion to the act of destruction. "She" would attach emotion and the range would include those of a mother, lover, seductress, fate, siren, dream, etc. "He" would more accurately invoke those of a competitor, warrior, challenger, father, master, protector, etc. While each range across all potential emotions, the source and reasonings will differ.
Take, for example, the subject of revenge. Examples motivations of traditional feminine revenge include unrequited love, payback for broken physical vanity, a betrayal of a son, jealousy, or gossip. Masculine revenge is more relevant for slavery, theft, murder, physical assault, or disrespect. Do note that these are gross generalizations and some great stories involve the exact opposites of these — for instance, a man vowing revenge on the one who scarred him. I only list them here to point toward why one would use "he" instead of "she".
Namely, the use of "he" would be apt whenever you would obviously turn an object into a specifically male entity if it actually had a gender. For instance: Moby Dick, as a car, would still be male. If you represent a car as an analogy for Moby Dick, it would be apt to use "he". You wouldn't have to but you could pull it off.
To come back to the male tornado: He may feel larger, slower, more angry and much more likely to sit around and individually smash - every - single - house by tossing them one by one into a nearby mountain.
Or not. All of this is entirely subjective, which is entirely the point.