Yes, you can buy legendary (orange) weapons in normal vending machines. I can not find any written souce, but I've personally purchased a Shredifier from a gun machine at Raiders HQ in Sanctuary.
I'd assume any legendary that is marked as "drops from any suitable loot source" in the wiki can spawn in a vending machine. Level of the item is equal to the level of vending machine, which is equal to area level - if you go to Southern Shelf on Normal, you'll forever see level 4-6-something items there. (Also, probably no legendary can spawn that low.) As for "class", the type of item is rolled first, than it has the chance to become legendary - no specific rules.
Also, as Dave mentions, there are Torgue machines with legendaries for Torgue tokens, and Seraph vendor with seraph equipment for Seraph crystals.