We present a general method for determining the masses and orbital parameters of binary millisecond pulsars with long orbital periods (P-orb much greater than 1 yr), using timing data in the form of pulse frequency derivatives. Our method can be used even when the available timing data cover only a small fraction of an orbit, but it requires high-precision measurements of up to five successive derivatives of the pulse frequency. With five derivatives a complete determination of the mass and orbital parameters is in principle possible (up to the usual inclination factor sin i). With less than five derivatives, only partial information can be obtained, but significant constraints can sometimes be placed on, e.g., the mass of the companion. We apply our method to analyze the properties of the second companion in the PSR B1620-26 triple system. We use the latest timing data for this system, including a recent detection of the fourth time derivative of the pulse frequency, to constrain the mass and orbital parameters of the second companion. We find that all possible solutions have a mass m(2) in the range 2.4 x 10(-4) M-. less than or equal to m(2) sin i(2) less than or equal to 1.2 x 10(-2) M-., i.e., almost certainly excluding a second companion of stellar mass and suggesting instead that the system contains a planet or brown dwarf. To further constrain this system, we have used preliminary measurements of the secular perturbations of the inner binary. Using Monte Carlo realizations of the triple configuration in three dimensions, we find the most probable value of in, to be 0.01 +/- 0.005 M-., corresponding to a distance of 38 +/- 6 AU from the center of mass of the inner binary (the errors indicate 80% confidence intervals). We also apply our method to analyze the planetary system around PSR B1257+12, where a distant, giant planet may be present in addition to the three well-established Earth-mass planets. We find that the simplest interpretation of the frequency derivatives implies the presence of a fourth planet with a mass of similar to 100 M+ in a circular orbit of radius similar to 40 AU.