Mix the oyster sauce, soy sauce, water, and cornstarch in a bowl. Set aside.
Pat the tofu dry and season lightly with salt. Heat about ¼ inch of oil in a wok or large pan over medium-high heat. Fry the tofu until golden, then transfer to a plate. Pour off most of the oil.
Season the shrimp with salt and pepper. Cook for about a minute per side, until pink and opaque. Transfer to the plate with the tofu.
Cook the onion and garlic for about 2 minutes. Add the tomatoes and cook until soft and starting to caramelize, about 3 minutes.
Add the carrots and green beans; stir-fry for 2 minutes. Stir in the chilies, if using.
Add the bean sprouts. Stir the sauce again, then pour it into the pan. Toss for about 3 minutes, until the sprouts soften slightly.
Add the tofu, shrimp, and scallion. Toss until heated through, then taste and season as needed.